vllm.scalar_type
¶
Classes:
-
ScalarType–ScalarType can represent a wide range of floating point and integer
ScalarType
dataclass
¶
ScalarType can represent a wide range of floating point and integer
types, in particular it can be used to represent sub-byte data types
(something that torch.dtype currently does not support). It is also
capable of representing types with a bias, i.e.:
stored_value = value + bias,
this is useful for quantized types (e.g. standard GPTQ 4bit uses a bias
of 8). The implementation for this class can be found in
csrc/core/scalar_type.hpp, these type signatures should be kept in sync
with that file.
Methods:
-
__str__–Naming generally follows: https://github.com/jax-ml/ml_dtypes
-
float_–Create a non-standard floating point type
-
float_IEEE754–Create a standard floating point type
-
has_bias–If the type has a non-zero bias.
-
has_infs–If the type is floating point and supports infinity.
-
int_–Create a signed integer scalar type (size_bits includes sign-bit).
-
is_floating_point–If the type is a floating point type.
-
is_ieee_754–If the type is a floating point type that follows IEEE 754
-
is_integer–If the type is an integer type.
-
is_signed–If the type is signed (i.e. has a sign bit), same as
signed -
max–Max representable value for this scalar type.
-
min–Min representable value for this scalar type.
-
uint–Create an unsigned integer scalar type.
Attributes:
-
bias(int) –bias used to encode the values in this scalar type
-
exponent(int) –Number of bits in the exponent if this is a floating point type
-
id(int) –Convert the ScalarType to an int which can be passed to pytorch custom
-
mantissa(int) –Number of bits in the mantissa if this is a floating point type,
-
nan_repr(NanRepr) –How NaNs are represent in this scalar type, returns NanRepr value.
-
signed(bool) –If the type is signed (i.e. has a sign bit)
_finite_values_only = False
class-attribute
instance-attribute
¶
Private: if infs are supported, used has_infs() instead.
bias
instance-attribute
¶
bias used to encode the values in this scalar type (value = stored_value - bias, default 0) for example if we store the type as an unsigned integer with a bias of 128 then the value 0 will be stored as 128 and -1 will be stored as 127 and 1 will be stored as 129.
exponent
instance-attribute
¶
Number of bits in the exponent if this is a floating point type (zero if this an integer type)
id
cached
property
¶
Convert the ScalarType to an int which can be passed to pytorch custom ops. This layout of the int must be kept in sync with the C++ ScalarType's from_id method.
mantissa
instance-attribute
¶
Number of bits in the mantissa if this is a floating point type, or the number bits representing an integer excluding the sign bit if this an integer type.
nan_repr = NanRepr.IEEE_754
class-attribute
instance-attribute
¶
How NaNs are represent in this scalar type, returns NanRepr value. (not applicable for integer types)
signed
instance-attribute
¶
If the type is signed (i.e. has a sign bit)
__str__()
¶
Naming generally follows: https://github.com/jax-ml/ml_dtypes
for floating point types (leading f) the scheme is:
float<size_bits>_e<exponent_bits>m<mantissa_bits>[flags]
flags:
- no-flags: means it follows IEEE 754 conventions
- f: means finite values only (no infinities)
- n: means nans are supported (non-standard encoding)
for integer types the scheme is:
[u]int<size_bits>[b<bias>]
- if bias is not present it means its zero
float_(exponent, mantissa, finite_values_only, nan_repr)
classmethod
¶
Create a non-standard floating point type (i.e. does not follow IEEE 754 conventions).
float_IEEE754(exponent, mantissa)
classmethod
¶
Create a standard floating point type (i.e. follows IEEE 754 conventions).
has_bias()
¶
If the type has a non-zero bias.
has_infs()
¶
If the type is floating point and supports infinity.
int_(size_bits, bias)
classmethod
¶
Create a signed integer scalar type (size_bits includes sign-bit).
is_floating_point()
¶
If the type is a floating point type.
is_ieee_754()
¶
If the type is a floating point type that follows IEEE 754 conventions
is_integer()
¶
If the type is an integer type.
is_signed()
¶
If the type is signed (i.e. has a sign bit), same as signed
added for consistency with:
https://pytorch.org/docs/stable/generated/torch.Tensor.is_signed.html
max()
¶
Max representable value for this scalar type. (accounting for bias if there is one)
min()
¶
Min representable value for this scalar type. (accounting for bias if there is one)
uint(size_bits, bias)
classmethod
¶
Create an unsigned integer scalar type.