torch π
Torch operations and objects.
Buffer π
Bases: CType
Wrapper for the struct vaccel_torch_buffer
C object.
Manages the creation and initialization of a C struct vaccel_torch_buffer
and provides access to it through Python properties.
Inherits
CType: Abstract base class for defining C data types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| bytes | bytearray | The buffer data to be passed to the C struct. | required |
Source code in vaccel/ops/torch/buffer.py
Tensor π
Bases: CType
Wrapper for the struct vaccel_torch_tensor
C object.
Manages the creation and initialization of a C struct vaccel_torch_tensor
and provides access to it through Python properties.
Inherits
CType: Abstract base class for defining C data types.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| list[int] | The dims to be passed to the C struct. | required |
| TensorType | The data_type to be passed to the C struct. | required |
| list[Any] | The data to be passed to the C struct. | required |
Source code in vaccel/ops/torch/tensor.py
data_type property
π
The tensor data type.
Returns:
Type | Description |
---|---|
TensorType | The data type of the tensor. |
dims property
π
shape property
π
value property
π
Returns the value of the underlying C struct.
Returns:
Type | Description |
---|---|
CData | The dereferenced 'struct vaccel_torch_tensor` |
as_bytelike π
as_bytelike() -> bytes | bytearray | memoryview
Returns the tensor data buffer as a byte-like object.
Returns:
Type | Description |
---|---|
bytes | bytearray | memoryview | The data of the tensor as a byte-like object. |
Source code in vaccel/ops/torch/tensor.py
as_memoryview π
as_memoryview() -> memoryview
Returns the tensor data buffer as memoryview.
Returns:
Type | Description |
---|---|
memoryview | The data of the tensor as memoryview. |
Source code in vaccel/ops/torch/tensor.py
as_numpy π
Returns the tensor data buffer as a NumPy array.
Returns:
Type | Description |
---|---|
ndarray | The data of the tensor as a NumPy array. |
Source code in vaccel/ops/torch/tensor.py
as_torch π
Returns the tensor as a PyTorch tensor.
Returns:
Type | Description |
---|---|
Tensor | The tensor as a PyTorch tensor. |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
Source code in vaccel/ops/torch/tensor.py
empty classmethod
π
empty() -> Tensor
Initializes a new empty Tensor
object.
The object has a NULL pointer in place of the C struct.
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_buffer classmethod
π
from_buffer(
dims: list[int], data_type: TensorType, data: bytes | bytearray | memoryview
) -> Tensor
Initializes a new Tensor
object from byte-like data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| list[int] | The dims to be passed to the C struct. | required |
| TensorType | The data_type to be passed to the C struct. | required |
| bytes | bytearray | memoryview | The data to be passed to the C struct. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_c_obj classmethod
π
Initializes a new Tensor
object from an existing C struct.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| CData | A pointer to a | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Source code in vaccel/ops/torch/tensor.py
from_numpy classmethod
π
Initializes a new Tensor
object from a NumPy array.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| ndarray | The NumPy array containing the tensor data. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Raises:
Type | Description |
---|---|
NotImplementedError | If NumPy is not installed. |
Source code in vaccel/ops/torch/tensor.py
from_torch classmethod
π
Initializes a new Tensor
object from a PyTorch tensor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| Tensor | The PyTorch tensor containing the tensor data. | required |
Returns:
Type | Description |
---|---|
Tensor | A new |
Raises:
Type | Description |
---|---|
NotImplementedError | If PyTorch is not installed. |
Source code in vaccel/ops/torch/tensor.py
TorchMixin π
Mixin providing Torch operations for a Session
.
This mixin is intended to be used in combination with BaseSession
and should not be instantiated on its own.
Intended usage
class Session(BaseSession, TorchMixin): ...
torch_jitload_forward π
torch_jitload_forward(
resource: Resource,
in_tensors: list[Tensor],
nr_out_tensors: int = 1,
run_options: Buffer | None = None,
) -> list[Tensor]
Performs the Torch jitload forward operation.
Wraps the vaccel_torch_jitload_forward()
C operation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
| Resource | A resource with the model to run. | required |
| list[Tensor] | The input tensors for the inference. | required |
| int | The number of output tensors. Defaults to 1. | 1 |
| Buffer | None | The inference options. | None |
Returns:
Type | Description |
---|---|
list[Tensor] | The output tensors |
Raises:
Type | Description |
---|---|
FFIError | If the C operation fails. |