easydel.inference.esurge.utils#

Utility functions and classes for the eSurge engine.

Provides helper classes and functions for working with immutable lists, array type checking, and other common operations.

Classes:

ConstantList: Immutable list wrapper that prevents modifications

Functions:

is_list_of_jax_arrays: Type guard for checking JAX array lists

Example

>>> from easydel.inference.esurge.utils import ConstantList
>>>
>>> # Create immutable list
>>> const_list = ConstantList([1, 2, 3])
>>> print(const_list[0])  # Works
>>> const_list.append(4)  # Raises Exception
class easydel.inference.esurge.utils.ConstantList(x: list[T])[source]#

Bases: Generic[T], Sequence

Immutable list wrapper that prevents modifications.

Provides read-only access to a list while preventing any modification operations. Useful for protecting data structures that should not be changed after creation.

Parameters

x – The list to wrap and make immutable.

Example

>>> const_list = ConstantList([1, 2, 3])
>>> print(const_list[0])  # 1
>>> print(len(const_list))  # 3
>>> const_list.append(4)  # Raises Exception
append(item)[source]#
clear()[source]#
extend(item)[source]#
index(value[, start[, stop]]) integer -- return first index of value.[source]#

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(item)[source]#
pop(item)[source]#
remove(item)[source]#
easydel.inference.esurge.utils.cdiv(a: int, b: int) int[source]#

Ceiling division.

easydel.inference.esurge.utils.chunk_list(lst: list[T], chunk_size: int)[source]#

Yield successive chunk_size chunks from lst.

easydel.inference.esurge.utils.get_dtype_size(dtype: Array) int[source]#

Get the size of the data type in bytes.

easydel.inference.esurge.utils.is_list_of(value: object, typ: type[T] | tuple[type[T], ...], *, check: Literal['first', 'all'] = 'first') TypeIs[list[T]][source]#
easydel.inference.esurge.utils.next_power_of_2(n) int[source]#

The next power of 2 (inclusive)

easydel.inference.esurge.utils.prev_power_of_2(n: int) int[source]#

The previous power of 2 (inclusive)

easydel.inference.esurge.utils.round_down(x: int, y: int) int[source]#
easydel.inference.esurge.utils.round_up(x: int, y: int) int[source]#
easydel.inference.esurge.utils.truncate_tokens(tokens, target_len: int, mode: str = 'left')[source]#