• >
  • torchtraining.cast
Shortcuts

torchtraining.cast

Cast tensors in a functional fashion.

Users can use this module to cast step outputs to desired type or to lower precision in order to save memory (though it shouldn’t be needed.)

class torchtraining.cast.As(other)[source]

Cast torch.Tensor to the same type as other.

Parameters

other (torch.Tensor) – Tensor according to which incoming tensor will be casted.

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.BFloat16(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to BFloat16.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

BFloat16

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Bool(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Bool.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Bool

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Byte(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Byte.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Byte

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Char(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Char.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Char

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Double(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Double.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Double

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Float(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Float.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Float

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

torchtraining.cast.Float16

alias of torchtraining.cast.Half

torchtraining.cast.Float32

alias of torchtraining.cast.Float

torchtraining.cast.Float64

alias of torchtraining.cast.Double

class torchtraining.cast.Half(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Half.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Half

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Int(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Int.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Int

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

torchtraining.cast.Int16

alias of torchtraining.cast.Short

torchtraining.cast.Int32

alias of torchtraining.cast.Int

torchtraining.cast.Int64

alias of torchtraining.cast.Long

torchtraining.cast.Int8

alias of torchtraining.cast.Char

class torchtraining.cast.Item[source]

Cast torch.Tensor instance to Item.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Item

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.List[source]

Cast torch.Tensor instance to List.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

List

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Long(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Long.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Long

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.MKLDNN[source]

Cast torch.Tensor instance to MKLDNN.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

MKLDNN

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Numpy[source]

Cast torch.Tensor instance to Numpy.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Numpy

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Short(memory_format=torch.preserve_format)[source]

Cast torch.Tensor instance to Short.

Note

IMPORTANT: Only torch.Tensor can be passed as memory_format is specified during casting.

Returns

Casted data

Return type

Short

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

class torchtraining.cast.Sparse(sparse_dims=None)[source]

Cast torch.Tensor to sparse format.

Parameters

sparse_dims (int, optional) – The number of sparse dimensions to include in the new sparse tensor. Default: None.

forward(data)[source]
Parameters

data (torch.Tensor) – Tensor to be casted

torchtraining.cast.UInt8

alias of torchtraining.cast.Byte