bittensor.tensor#

Module Contents#

Classes#

tensor

Tensor

Represents a Tensor object.

Functions#

cast_dtype(raw)

Casts the raw value to a string representing the torch data type.

cast_shape(raw)

Casts the raw value to a string representing the tensor shape.

Attributes#

TORCH_DTYPES

bittensor.tensor.TORCH_DTYPES#
bittensor.tensor.cast_dtype(raw)#

Casts the raw value to a string representing the torch data type.

Parameters:

raw (Union[None, torch.dtype, str]) – The raw value to cast.

Returns:

The string representing the torch data type.

Return type:

str

Raises:

Exception – If the raw value is of an invalid type.

bittensor.tensor.cast_shape(raw)#

Casts the raw value to a string representing the tensor shape.

Parameters:

raw (Union[None, List[int], str]) – The raw value to cast.

Returns:

The string representing the tensor shape.

Return type:

str

Raises:

Exception – If the raw value is of an invalid type or if the list elements are not of type int.

class bittensor.tensor.tensor#
class bittensor.tensor.Tensor(**data)#

Bases: pydantic.BaseModel

Represents a Tensor object.

Parameters:

data (Any) –

buffer#

Tensor buffer data.

Type:

Optional[str]

dtype#

Tensor data type.

Type:

str

shape#

Tensor shape.

Type:

List[int]

class Config#
validate_assignment = True#
buffer: str | None#
dtype: str#
_extract_dtype#
shape: List[int]#
_extract_shape#
tensor()#
Return type:

torch.Tensor

tolist()#
Return type:

List[object]

numpy()#
Return type:

numpy.ndarray

deserialize()#

Deserializes the Tensor object.

Returns:

The deserialized tensor object.

Return type:

torch.Tensor

Raises:

Exception – If the deserialization process encounters an error.

static serialize(tensor)#

Serializes the given tensor.

Parameters:

tensor (torch.Tensor) – The tensor to serialize.

Returns:

The serialized tensor.

Return type:

Tensor

Raises:

Exception – If the serialization process encounters an error.