Skip to main content
Version: 24.8.0

ClikaModule

Instance variables

clika_distributed_is_available_and_initialized: bool

Returns True if distributed environment is available and initialized (either FSDP or DDP) else 'False'

clika_distributed_is_global_main_node: bool

Returns 'True' if the current instance running is the global main node in the distributed training, else 'False'

clika_distributed_is_local_main_node: bool

Returns 'True' if the current instance running is the main node locally (same machine) in the distributed training, else 'False'

clika_distributed_world_rank: int

Returns 'int' with the rank of the current instance in the Distributed Training World

clika_distributed_world_size: int

Returns 'int' with the number of Instances currently participating in the Distributed Training World

clika_input_names: list

Returns List[str] of the input names of the current ClikaModule

clika_output_names: list

Returns List[str] of the output names of the current ClikaModule

clika_is_calibration_required: bool

Returns 'True' if the Algorithms being used (QAT, ...) in this current ClikaModule requiring Data for Calibration else 'False'

clika_is_ddp_initialized: bool

Returns 'True' if Distributed Data Parallel is used else 'False'

clika_is_fsdp_initialized: bool

Returns 'True' if Fully Sharded Data Parallel is used else 'False'

clika_num_inputs: int

Returns 'int' - the number of inputs in this ClikaModule

clika_num_outputs: int

Returns 'int' - the number of outputs in this ClikaModule

clika_num_non_trainable_parameters: int

Returns 'int' - the number of non-trainable parameters in the model

clika_num_trainable_parameters: int

Returns 'int' - the number of trainable parameters in the model

clika_total_num_parameters: int

Returns 'int' - the number of trainable and non-trainable parameters in the model

Static methods

clika_from_serialized(data: bytes) ‑> clika_ace.functional.functional_api.ClikaModule

Loads `ClikaModule` from serialized data that was generated from `ClikaModule` serialization.

Args:
data: bytes - Serialized `ClikaModule`

Returns:
`ClikaModule`

Methods

bfloat16(self) ‑> clika_ace.functional.functional_api.ClikaModule

Casts all floating point parameters and buffers to ``bfloat16`` datatype.

.. note::
This method modifies the module in-place.

Returns:
Module: self

buffers(self, recurse: bool = True) ‑> List[torch.Tensor]

Returns an iterator over module buffers.

Args:
recurse (bool): if True, then yields buffers of this module
and all submodules. Otherwise, yields only buffers that
are direct members of this module.

Yields:
torch.Tensor: module buffer

clika_clear_cache(self) ‑> None

Args:
Clears RAM + VRAM if there is anything to clear. Otherwise no-op.

Returns:
None

clika_clip_grad_norm_(self, max_norm: Union[int, float], norm_type: Union[int, float]) ‑> torch.Tensor

Args:
Clips Grad Norm and returns the Norm.

Returns:
torch.Tensor - the Norm of grads

clika_export(self, file: Union[str, pathlib.Path, _io.BytesIO], example_inputs: Optional[Any] = None, input_names: Optional[List[str]] = None, output_names: Optional[List[str]] = None, dynamic_axes: Union[Mapping[str, Mapping[int, str]], Mapping[str, Sequence[int]]] = None, **kwargs: Optional[Dict[str, Any]]) ‑> object

Similarly to `torch.onnx.export`

Args:
file - Union[str, pathlib.Path, io.BytesIO] - Path or File Descriptor to save the file
example_inputs - Arguments for the model to inference on and trace the graph with
input_names - Optional[List[str]] - New names for the inputs of the deployed model
output_names - Optional[List[str]] - New names for the outputs of the deployed model
dynamic_axes: Union[Mapping[str, Mapping[int, str]], Mapping[str, Sequence[int]]]


Returns:

clika_free_storage(self) ‑> bool

Discards the model and frees the memory occupied by the `ClikaModule`

Args:

Returns:
bool - True if successful False if already freed.

clika_generate_dummy_inputs(self) ‑> dict

Generates dummy inputs based on the Inputs of the `ClikaModule` where key is the input name and value is a torch.Tensor

Args:


Returns:
Dict[str, torch.Tensor]

clika_get_node_names_grouped_by_depth(self) ‑> List[List[str]]

Args:


Returns:

clika_get_runtime_analysis(self, *args, **kwargs) ‑> Tuple[Dict[str, float], Dict[str, float]]

Args:


Returns:

clika_get_topologically_sorted_node_names(self) ‑> List[str]

Returns the names of the nodes in the `ClikaModule` in a topologically sorted order

Args:


Returns:
List[str] - names of the nodes in a topological order

clika_initialize_algorithms(self) ‑> None

Not recommended to use externally at this point.

Args:


Returns:

clika_initialize_distributed_ddp_model(self, offload_params: bool = False, offload_activations: bool = False) ‑> clika_ace.functional.functional_api.ClikaModule

Not recommended to use externally at this point.

Args:


Returns:

clika_initialize_distributed_fsdp_model(self, offload_params: bool = False, offload_activations: bool = False) ‑> clika_ace.functional.functional_api.ClikaModule

Not recommended to use externally at this point.

Args:


Returns:

clika_initialize_from_pytorch(self, model: torch.nn.modules.module.Module, example_inputs: Any, **kwargs) ‑> clika_ace.functional.functional_api.ClikaModule

Not recommended to use externally at this point.

Args:


Returns:

clika_save(self, path: Union[str, pathlib.Path]) ‑> None

Serializing the `ClikaModule` to bytes and saves it to

Args:
path - Union[str, pathlib.Path] where to save the `ClikaModule` to

Returns:
bytes - Serialized `ClikaModule`

clika_serialize(self) ‑> bytes

Serializing the `ClikaModule` to bytes

Args:

Returns:
bytes - Serialized `ClikaModule`

clika_set_activations_offload(self, name: str, enabled: bool = True, path_to_storage: Optional[str] = None) ‑> List[str]

Sets activations offload to reduce VRAM memory consumption.
Trade Speed for Memory.
Args:
name: str: name or pattern
enabled: bool - whether to enable or disable
path_to_storage: Optional[str] - Whether or not to store the activations in an existing directory instead of CPU.

Returns:
List[str] of the names of layers that it was applied on

clika_set_parameters_offload(self, name: str, enabled: bool = True) ‑> List[str]

Sets parameters offload to reduce VRAM memory consumption.
Trade Speed for Memory.

Args:
name: str: name or pattern
enabled: bool - whether to enable or disable
Returns:
List[str] of the names of layers that it was applied on

clika_visualize(self, path: Union[str, pathlib.Path]) ‑> str

Save svg and dotfile to Path given

Args:
path: str or Path obj - Path to a directory or a file to be created

Returns:
str - Path to the new '.svg' file

cpu(self) ‑> clika_ace.functional.functional_api.ClikaModule

Moves all model parameters and buffers to the CPU.

.. note::
This method modifies the module in-place.

Returns:
Module: self

cuda(self, device: Union[int, torch.device, ForwardRef(None)] = None) ‑> clika_ace.functional.functional_api.ClikaModule

Moves all model parameters and buffers to the GPU.

This also makes associated parameters and buffers different objects. So
it should be called before constructing optimizer if the module will
live on GPU while being optimized.

.. note::
This method modifies the module in-place.

Args:
device (int, optional): if specified, all parameters will be
copied to that device

Returns:
Module: self

eval(self) ‑> clika_ace.functional.functional_api.ClikaModule

Sets the module in evaluation mode.

This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
etc.

This is equivalent with :meth:`self.train(False) <torch.nn.Module.train>`.

See :ref:`locally-disable-grad-doc` for a comparison between
`.eval()` and several similar mechanisms that may be confused with it.

Returns:
Module: self

float(self) ‑> clika_ace.functional.functional_api.ClikaModule

Casts all floating point parameters and buffers to ``float`` datatype.

.. note::
This method modifies the module in-place.

Returns:
Module: self

float16(self) ‑> clika_ace.functional.functional_api.ClikaModule

Casts all floating point parameters and buffers to ``float16`` datatype.

.. note::
This method modifies the module in-place.

Returns:
Module: self

float32(self) ‑> clika_ace.functional.functional_api.ClikaModule

Casts all floating point parameters and buffers to ``float`` datatype.

.. note::
This method modifies the module in-place.

Returns:
Module: self

forward(self, *args, **kwargs) ‑> Any

Defines the computation performed at every call.

Should be overridden by all subclasses.

.. note::
Although the recipe for forward pass needs to be defined within
this function, one should call the :class:`Module` instance afterwards
instead of this since the former takes care of running the
registered hooks while the latter silently ignores them.

half(self) ‑> clika_ace.functional.functional_api.ClikaModule

Casts all floating point parameters and buffers to ``half`` datatype.

.. note::
This method modifies the module in-place.

Returns:
Module: self

load_state_dict(self, state_dict: Mapping[str, Any], strict: bool = True, assign: bool = False)

Copies parameters and buffers from :attr:`state_dict` into
this module and its descendants. If :attr:`strict` is ``True``, then
the keys of :attr:`state_dict` must exactly match the keys returned
by this module's :meth:`~torch.nn.Module.state_dict` function.

Args:
state_dict (dict): a dict containing parameters and
persistent buffers.
strict (bool, optional): whether to strictly enforce that the keys
in :attr:`state_dict` match the keys returned by this module's
:meth:`~torch.nn.Module.state_dict` function. Default: ``True``

Returns:
``NamedTuple`` with ``missing_keys`` and ``unexpected_keys`` fields:
* **missing_keys** is a list of str containing the missing keys
* **unexpected_keys** is a list of str containing the unexpected keys

named_buffers(self, prefix: Optional[str] = None, recurse: bool = True, remove_duplicate: bool = True) ‑> List[Tuple[str, torch.Tensor]]

Returns an iterator over module buffers, yielding both the
name of the buffer as well as the buffer itself.

Args:
prefix (str): prefix to prepend to all buffer names.
recurse (bool, optional): if True, then yields buffers of this module
and all submodules. Otherwise, yields only buffers that
are direct members of this module. Defaults to True.
remove_duplicate (bool, optional): whether to remove the duplicated buffers in the result. Defaults to True.

Yields:
(str, torch.Tensor): Tuple containing the name and buffer

named_parameters(self, prefix: Optional[str] = None, recurse: bool = True, remove_duplicate: bool = True) ‑> List[Tuple[str, torch.nn.parameter.Parameter]]

Returns an iterator over module parameters, yielding both the
name of the parameter as well as the parameter itself.

Args:
prefix (str): prefix to prepend to all parameter names.
recurse (bool): if True, then yields parameters of this module
and all submodules. Otherwise, yields only parameters that
are direct members of this module.
remove_duplicate (bool, optional): whether to remove the duplicated
parameters in the result. Defaults to True.

Yields:
(str, Parameter): Tuple containing the name and parameter

parameters(self, recurse: bool = True) ‑> List[torch.nn.parameter.Parameter]

Returns an iterator over module parameters.

This is typically passed to an optimizer.

Args:
recurse (bool): if True, then yields parameters of this module
and all submodules. Otherwise, yields only parameters that
are direct members of this module.

Yields:
Parameter: module parameter

requires_grad_(self, requires_grad: bool = True) ‑> clika_ace.functional.functional_api.ClikaModule

Change if autograd should record operations on parameters in this
module.

This method sets the parameters' :attr:`requires_grad` attributes
in-place.

This method is helpful for freezing part of the module for finetuning
or training parts of a model individually (e.g., GAN training).

See :ref:`locally-disable-grad-doc` for a comparison between
`.requires_grad_()` and several similar mechanisms that may be confused with it.

Args:
requires_grad (bool): whether autograd should record operations on
parameters in this module. Default: ``True``.

Returns:
Module: self

state_dict(self, *args, destination: Optional[dict] = None, prefix: Optional[str] = None, keep_vars: bool = False) ‑> collections.OrderedDict

Returns a dictionary containing references to the whole state of the module.

Both parameters and persistent buffers (e.g. running averages) are
included. Keys are corresponding parameter and buffer names.
Parameters and buffers set to ``None`` are not included.

.. note::
The returned object is a shallow copy. It contains references
to the module's parameters and buffers.

.. warning::
Currently ``state_dict()`` also accepts positional arguments for
``destination``, ``prefix`` and ``keep_vars`` in order. However,
this is being deprecated and keyword arguments will be enforced in
future releases.

.. warning::
Please avoid the use of argument ``destination`` as it is not
designed for end-users.

Args:
destination (dict, optional): If provided, the state of module will
be updated into the dict and the same object is returned.
Otherwise, an ``OrderedDict`` will be created and returned.
Default: ``None``.
prefix (str, optional): a prefix added to parameter and buffer
names to compose the keys in state_dict. Default: ``''``.
keep_vars (bool, optional): by default the :class:`~torch.Tensor` s
returned in the state dict are detached from autograd. If it's
set to ``True``, detaching will not be performed.
Default: ``False``.

Returns:
dict:
a dictionary containing a whole state of the module

to(self, *args, **kwargs)

Moves and/or casts the parameters and buffers.

This can be called as

.. function:: to(device=None, dtype=None, non_blocking=False)
:noindex:

.. function:: to(dtype, non_blocking=False)
:noindex:

.. function:: to(tensor, non_blocking=False)
:noindex:

.. function:: to(memory_format=torch.channels_last)
:noindex:

Its signature is similar to :meth:`torch.Tensor.to`, but only accepts
floating point or complex :attr:`dtype`\ s. In addition, this method will
only cast the floating point or complex parameters and buffers to :attr:`dtype`
(if given). The integral parameters and buffers will be moved
:attr:`device`, if that is given, but with dtypes unchanged. When
:attr:`non_blocking` is set, it tries to convert/move asynchronously
with respect to the host if possible, e.g., moving CPU Tensors with
pinned memory to CUDA devices.

See below for examples.

.. note::
This method modifies the module in-place.

Args:
device (:class:`torch.device`): the desired device of the parameters
and buffers in this module
dtype (:class:`torch.dtype`): the desired floating point or complex dtype of
the parameters and buffers in this module
tensor (torch.Tensor): Tensor whose dtype and device are the desired
dtype and device for all parameters and buffers in this module
memory_format (:class:`torch.memory_format`): the desired memory
format for 4D parameters and buffers in this module (keyword
only argument)

Returns:
Module: self

train(self, mode: bool = True) ‑> clika_ace.functional.functional_api.ClikaModule

Sets the module in training mode.

This has any effect only on certain modules. See documentations of
particular modules for details of their behaviors in training/evaluation
mode, if they are affected, e.g. :class:`Dropout`, :class:`BatchNorm`,
etc.

Args:
mode (bool): whether to set training mode (``True``) or evaluation
mode (``False``). Default: ``True``.

Returns:
Module: self

zero_grad(self, set_to_none: bool = True) ‑> None

Sets gradients of all model parameters to zero. See similar function
under :class:`torch.optim.Optimizer` for more context.

Args:
set_to_none (bool): instead of setting to zero, set the grads to None.
See :meth:`torch.optim.Optimizer.zero_grad` for details.