Vllm.ScalarType (VLLM v0.3.0)

Copy Markdown View Source

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.

Summary

Functions

Python method ScalarType._floating_point_max.

Python method ScalarType._floating_point_max_int.

Python method ScalarType._raw_max.

Python method ScalarType._raw_min.

Create a standard floating point type

Python method ScalarType.from_id.

If the type has a non-zero bias

If the type is floating point and supports infinity

Python method ScalarType.has_nans.

Create a signed integer scalar type (size_bits includes sign-bit).

If the type is a floating point type

If the type is a floating point type that follows IEEE 754

If the type is an integer type

If the type is signed (i.e. has a sign bit), same as signed

Max representable value for this scalar type.

Min representable value for this scalar type.

Initialize self. See help(type(self)) for accurate signature.

Create an unsigned integer scalar type.

Types

t()

@opaque t()

Functions

_floating_point_max(ref, opts \\ [])

@spec _floating_point_max(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, float()} | {:error, Snakepit.Error.t()}

Python method ScalarType._floating_point_max.

Returns

  • float()

_floating_point_max_int(ref, opts \\ [])

@spec _floating_point_max_int(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, integer()} | {:error, Snakepit.Error.t()}

Python method ScalarType._floating_point_max_int.

Returns

  • integer()

_raw_max(ref, opts \\ [])

@spec _raw_max(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Python method ScalarType._raw_max.

Returns

  • term()

_raw_min(ref, opts \\ [])

@spec _raw_min(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Python method ScalarType._raw_min.

Returns

  • term()

float_(ref, exponent, mantissa, finite_values_only, nan_repr, opts \\ [])

@spec float_(
  SnakeBridge.Ref.t(),
  integer(),
  integer(),
  boolean(),
  Vllm.ScalarType.NanRepr.t(),
  keyword()
) :: {:ok, t()} | {:error, Snakepit.Error.t()}

Create a non-standard floating point type

(i.e. does not follow IEEE 754 conventions).

Parameters

  • exponent (integer())
  • mantissa (integer())
  • finite_values_only (boolean())
  • nan_repr (Vllm.ScalarType.NanRepr.t())

Returns

  • Vllm.ScalarType.t()

float_ieee754(ref, exponent, mantissa, opts \\ [])

@spec float_ieee754(SnakeBridge.Ref.t(), integer(), integer(), keyword()) ::
  {:ok, t()} | {:error, Snakepit.Error.t()}

Create a standard floating point type

(i.e. follows IEEE 754 conventions).

Parameters

  • exponent (integer())
  • mantissa (integer())

Returns

  • Vllm.ScalarType.t()

from_id(ref, scalar_type_id, opts \\ [])

@spec from_id(SnakeBridge.Ref.t(), integer(), keyword()) ::
  {:ok, term()} | {:error, Snakepit.Error.t()}

Python method ScalarType.from_id.

Parameters

  • scalar_type_id (integer())

Returns

  • term()

has_bias(ref, opts \\ [])

@spec has_bias(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

If the type has a non-zero bias

Returns

  • boolean()

has_infs(ref, opts \\ [])

@spec has_infs(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

If the type is floating point and supports infinity

Returns

  • boolean()

has_nans(ref, opts \\ [])

@spec has_nans(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

Python method ScalarType.has_nans.

Returns

  • boolean()

id(ref)

@spec id(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()}

int_(ref, size_bits, bias, opts \\ [])

@spec int_(SnakeBridge.Ref.t(), integer(), term(), keyword()) ::
  {:ok, t()} | {:error, Snakepit.Error.t()}

Create a signed integer scalar type (size_bits includes sign-bit).

Parameters

  • size_bits (integer())
  • bias (term())

Returns

  • Vllm.ScalarType.t()

is_floating_point(ref, opts \\ [])

@spec is_floating_point(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

If the type is a floating point type

Returns

  • boolean()

is_ieee_754(ref, opts \\ [])

@spec is_ieee_754(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

If the type is a floating point type that follows IEEE 754

conventions

Returns

  • boolean()

is_integer(ref, opts \\ [])

@spec is_integer(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

If the type is an integer type

Returns

  • boolean()

is_signed(ref, opts \\ [])

@spec is_signed(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, boolean()} | {:error, Snakepit.Error.t()}

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

Returns

  • boolean()

max(ref, opts \\ [])

@spec max(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Max representable value for this scalar type.

(accounting for bias if there is one)

Returns

  • term()

min(ref, opts \\ [])

@spec min(
  SnakeBridge.Ref.t(),
  keyword()
) :: {:ok, term()} | {:error, Snakepit.Error.t()}

Min representable value for this scalar type.

(accounting for bias if there is one)

Returns

  • term()

nan_repr(ref)

@spec nan_repr(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()}

new(exponent, mantissa, signed, bias, args, opts \\ [])

@spec new(integer(), integer(), boolean(), integer(), [term()], keyword()) ::
  {:ok, SnakeBridge.Ref.t()} | {:error, Snakepit.Error.t()}

Initialize self. See help(type(self)) for accurate signature.

Parameters

  • exponent (integer())
  • mantissa (integer())
  • signed (boolean())
  • bias (integer())
  • finite_values_only (boolean() default: False)
  • nan_repr (Vllm.ScalarType.NanRepr.t() default: <NanRepr.IEEE_754: 1>)

size_bits(ref)

@spec size_bits(SnakeBridge.Ref.t()) :: {:ok, term()} | {:error, Snakepit.Error.t()}

uint(ref, size_bits, bias, opts \\ [])

@spec uint(SnakeBridge.Ref.t(), integer(), term(), keyword()) ::
  {:ok, t()} | {:error, Snakepit.Error.t()}

Create an unsigned integer scalar type.

Parameters

  • size_bits (integer())
  • bias (term())

Returns

  • Vllm.ScalarType.t()