bittensor.tensor#

Module Contents#

Classes#

Tensor

Represents a Tensor object.

tensor

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#
class bittensor.tensor.Tensor(**data)#

Bases: pydantic.BaseModel

Represents a Tensor object.

Parameters:
  • buffer (Optional[str]) – Tensor buffer data.

  • dtype (str) – Tensor data type.

  • shape (List[int]) – Tensor shape.

  • data (Any) –

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

Deserializes the Tensor object.

Returns:

The deserialized tensor object.

Return type:

torch.Tensor

Raises:

Exception – If the deserialization process encounters an error.

numpy()#
Return type:

numpy.ndarray

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.

tensor()#
Return type:

torch.Tensor

tolist()#
Return type:

List[object]

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#