concepts.dsl.executors.value_quantizers.PyObjectStore#

class PyObjectStore[source]#

Bases: object

A store for Python objects. This class is used to map Python objects to integers (so that they can be stored in a TensorValue object) and vice versa.

Methods

add(typename, python_object)

The lowest-API to add a Python object to the store.

checkpoint()

A context manager that can be used to checkpoint all the stored Python objects.

make_batched_value(typename, pyobj_list[, ...])

Make a TensorValue object from a list of (or nested lists of) Python objects.

make_value(typename, python_object)

Make a TensorValue object from a single Python object.

retrieve(typename, index)

The lowest-API to retrieve a Python object from the store.

retrieve_value(value)

Retrieve one or multiple Python object from the store.

Attributes

executor

The executor that uses this object store.

domain

The underlying domain for the PyObjectStore.

__init__(executor)[source]#

Initialize the PyObjectStore object.

Parameters:

executor (TensorValueExecutorBase) – the executor that uses this object store.

__new__(**kwargs)#
add(typename, python_object)[source]#

The lowest-API to add a Python object to the store. Most of the time, you should use other higher-level APIs such as make_value() and make_batched_value().

Parameters:
  • typename (str) – the typename of the Python object.

  • python_object (Any) – the Python object to add.

Returns:

the index of the Python object in the store.

Return type:

int

checkpoint()[source]#

A context manager that can be used to checkpoint all the stored Python objects. This is useful when you performs a series of executions and want to restore the objects to save memory.

make_batched_value(typename, pyobj_list, batch_variables=None)[source]#

Make a TensorValue object from a list of (or nested lists of) Python objects.

Parameters:
  • typename (str) – the typename of the Python object.

  • pyobj_list (List[Any]) – the list of (or nested lists of) Python objects.

  • batch_variables (Sequence[str] | None) – the batch variables of the TensorValue object.

Return type:

TensorValue

make_value(typename, python_object)[source]#

Make a TensorValue object from a single Python object.

Parameters:
  • typename (str) – the typename of the Python object.

  • python_object (Any) – the Python object to add.

Returns:

the TensorValue object.

Return type:

TensorValue

retrieve(typename, index)[source]#

The lowest-API to retrieve a Python object from the store. Most of the time, you should use other higher-level APIs such as retrieve_value().

Parameters:
  • typename (str) –

  • index (int) –

Return type:

Any

retrieve_value(value)[source]#

Retrieve one or multiple Python object from the store. When the value is a batched value, this function will return a list of (or nested lists of) Python objects.

Parameters:

value (TensorValue) –

Return type:

Any | List[Any]

domain: DSLDomainBase#

The underlying domain for the PyObjectStore.

executor: TensorValueExecutorBase#

The executor that uses this object store.