1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Torch interop registration hook.
//!
//! The actual bridging logic lives in the Python layer at
//! `python/oxillama_py/torch_helper.py`. This file exists only to keep
//! the module structure explicit and to provide a registration entry-point
//! that can be extended if Rust-level helpers are ever needed.
//!
//! The bridge is purely Python-side:
//! 1. `torch_helper.py` monkey-patches `Engine.logits_torch` and
//! `Engine.embeddings_torch` onto the class at import time.
//! 2. Both methods call the already-shipped `logits_dlpack()` /
//! `embeddings_dlpack()` Rust methods and convert the `PyCapsule` to a
//! `torch.Tensor` via `torch.from_dlpack(capsule)`.
//! 3. Torch is imported lazily inside each method so that the absence of
//! PyTorch does not prevent the rest of the package from loading.
use *;
/// Register torch interop helpers in the Python module.
///
/// Currently a no-op at the Rust level — the monkey-patching is performed
/// in `__init__.py` via `torch_helper.try_patch(...)`.