vllm.scalar_type
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.
Source code in vllm/scalar_type.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 |
|
_finite_values_only
class-attribute
instance-attribute
¶
_finite_values_only: bool = False
Private: if infs are supported, used has_infs()
instead.
bias
instance-attribute
¶
bias: int
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
¶
exponent: int
Number of bits in the exponent if this is a floating point type (zero if this an integer type)
id
cached
property
¶
id: int
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
¶
mantissa: int
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
class-attribute
instance-attribute
¶
How NaNs are represent in this scalar type, returns NanRepr value. (not applicable for integer types)
__init__
¶
__init__(
exponent: int,
mantissa: int,
signed: bool,
bias: int,
_finite_values_only: bool = False,
nan_repr: NanRepr = IEEE_754,
) -> None
__str__
¶
__str__() -> 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
Source code in vllm/scalar_type.py
_floating_point_max_int
¶
_floating_point_max_int() -> int
Source code in vllm/scalar_type.py
_raw_max
¶
Source code in vllm/scalar_type.py
_raw_min
¶
Source code in vllm/scalar_type.py
float_
classmethod
¶
float_(
exponent: int,
mantissa: int,
finite_values_only: bool,
nan_repr: NanRepr,
) -> ScalarType
Create a non-standard floating point type (i.e. does not follow IEEE 754 conventions).
Source code in vllm/scalar_type.py
float_IEEE754
classmethod
¶
float_IEEE754(exponent: int, mantissa: int) -> ScalarType
Create a standard floating point type (i.e. follows IEEE 754 conventions).
Source code in vllm/scalar_type.py
int_
classmethod
¶
int_(size_bits: int, bias: Optional[int]) -> ScalarType
Create a signed integer scalar type (size_bits includes sign-bit).
Source code in vllm/scalar_type.py
is_ieee_754
¶
is_ieee_754() -> bool
If the type is a floating point type that follows IEEE 754 conventions
is_signed
¶
is_signed() -> bool
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
classmethod
¶
uint(size_bits: int, bias: Optional[int]) -> ScalarType
Create a unsigned integer scalar type.
scalar_types
¶
Source code in vllm/scalar_type.py
float8_e4m3fn
class-attribute
instance-attribute
¶
float8_e4m3fn = float_(4, 3, True, EXTD_RANGE_MAX_MIN)