ClikaModule
Instance variables (Properties)
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[str]
Returns
List[str]
of the input names of the currentClikaModule
.
clika_output_names: List[str]
Returns
List[str]
of the output names of the currentClikaModule
.
clika_is_calibration_required: bool
Returns
True
if the Algorithms being used (QAT, ...) in this currentClikaModule
require 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 thisClikaModule
.
clika_num_outputs: int
Returns
int
- the number of outputs in thisClikaModule
.
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_load(path: Union[str, pathlib.Path]) ‑> clika_ace.functional.functional_api.ClikaModule
Loads a ClikaModule from a previously saved file.
Reads the serialized bytes from the file and uses
clika_from_serialized
to reconstruct the instance.Args: path: The file path (string or Path object) from which to load the model state.
Returns: A new ClikaModule instance with the loaded state.
clika_from_serialized(data: bytes) ‑> clika_ace.functional.functional_api.ClikaModule
Loads
ClikaModule
from serialized data that was generated fromClikaModule
serialization.Args: data (bytes): Serialized
ClikaModule
.Returns:
ClikaModule
: The loaded ClikaModule instance.
Methods
__init__(self, deployment_settings: Optional[BaseDeploymentSettings] = None, verbosity: int = logging.DEBUG, logs_dir: Optional[Union[pathlib.Path, str]] = None, *args, **kwargs)
Initializes the ClikaModule wrapper.
Args: deployment_settings: Optional deployment settings specifying the target framework. verbosity: Logging level (e.g., logging.DEBUG, logging.INFO). logs_dir: Optional directory path to store CLIKA logs. *args: Additional positional arguments (currently unused). **kwargs: Additional keyword arguments (currently unused).
clika_save(self, path: Union[str, pathlib.Path]) -> None
Saves the internal CLIKA model state to a file.
This typically involves calling
clika_serialize()
and writing the resulting bytes to the specified file path.Args: path: The file path (string or Path object) where the model state should be saved.
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:
ClikaModule
: self
buffers(self, recurse: bool = True) ‑> Iterator[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. Default:
True
.Yields: torch.Tensor: module buffer
clika_clear_cache(self) ‑> None
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] = 2.0) ‑> torch.Tensor
Clips gradient norm of an iterable of parameters. The norm is computed over all gradients together, as if they were concatenated into a single vector. Gradients are modified in-place. See
torch.nn.utils.clip_grad_norm_
for more details.Args: max_norm (float or int): max norm of the gradients. norm_type (float or int): type of the used p-norm. Can be
'inf'
for infinity norm. Default:2.0
.Returns: torch.Tensor: Total norm of the parameters (viewed as a single vector).
clika_deploy(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, force_new_engine: bool = False, **kwargs: Optional[Dict[str, Any]]) ‑> Optional[InferenceModel]
Exports the model to ONNX format and then deploys it using the specified backend framework (e.g., TensorRT, OpenVINO) if configured during initialization.
Args: file (Union[str, pathlib.Path, io.BytesIO]): Path or file descriptor to save the exported ONNX model. example_inputs (Optional[Any]): Example inputs for ONNX export tracing. input_names (Optional[List[str]]): Names for the ONNX model's inputs. output_names (Optional[List[str]]): Names for the ONNX model's outputs. dynamic_axes (Optional[Union[...]]): Configuration for dynamic axes in the ONNX model. force_new_engine (bool): If deploying to TensorRT, force rebuilding the engine even if one exists. Default:
False
. **kwargs (Optional[Dict[str, Any]]): Additional keyword arguments passed toclika_export
.Returns: Optional[InferenceModel]: An
InferenceModel
instance wrapping the deployed engine/model if deployment is successful and supported, otherwiseNone
.
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
Exports the
ClikaModule
to the ONNX format. Similar totorch.onnx.export
.Args: file (Union[str, pathlib.Path, io.BytesIO]): Path or file descriptor to save the ONNX file. example_inputs (Optional[Any]): Arguments for the model to inference on and trace the graph. input_names (Optional[List[str]]): Names to assign to the input nodes of the graph. output_names (Optional[List[str]]): Names to assign to the output nodes of the graph. dynamic_axes (Optional[Union[...]]): Specifies dynamic axes in the ONNX graph. **kwargs (Optional[Dict[str, Any]]): Additional keyword arguments passed to the internal ONNX exporter.
Returns: object: The exported ONNX model object (typically
onnx.ModelProto
).
clika_get_node_name_to_type_mapping(self) ‑> dict
Retrieves a mapping from internal node names to their operation types.
Returns: dict: A dictionary where keys are node names (str) and values are their corresponding operation types (str, e.g., 'Conv', 'MatMul').
clika_initialize_distributed_ddp_model(self, offload_params: bool = False, offload_activations: bool = False) ‑> clika_ace.functional.functional_api.ClikaModule
Initializes the internal model for Distributed Data Parallel (DDP) training. Wraps the model with DDP and potentially configures parameter/activation offloading if supported by the backend.
Args: offload_params (bool): Whether to attempt offloading parameters. Default:
False
. offload_activations (bool): Whether to attempt offloading activations. Default:False
.Returns:
ClikaModule
: self
clika_initialize_distributed_fsdp_model(self, offload_params: bool = False, offload_activations: bool = False) ‑> clika_ace.functional.functional_api.ClikaModule
Initializes the internal model for Fully Sharded Data Parallel (FSDP) training. Wraps the model with FSDP and potentially configures parameter/activation offloading.
Args: offload_params (bool): Whether to enable FSDP's parameter CPU offloading. Default:
False
. offload_activations (bool): Whether to enable FSDP's activation CPU offloading/checkpointing. Default:False
.Returns:
ClikaModule
: self
clika_initialize_from_pytorch(self, *, model: torch.nn.Module, tracing_inputs: Any, calibration_inputs: Any, quantization_settings: Optional[QuantizationSettings] = None, layer_quantization_settings: Optional[Dict[str, LayerQuantizationSettings]] = None, pruning_settings: Optional[PruningSettings] = None, layer_pruning_settings: Optional[Dict[str, LayerQuantizationSettings]] = None, lora_settings: Optional[LoraSettings] = None, is_model_pretrained: bool = True, discard_input_model: bool = True, huggingface_config: Optional[dict] = None, is_dry_run: bool = False, **kwargs) ‑> clika_ace.functional.functional_api.ClikaModule
Initializes the internal CLIKA model from a PyTorch nn.Module. This method traces the model, performs calibration, applies specified compression settings (quantization, pruning, LoRA), and prepares the model for further use within the CLIKA framework.
Args: model (torch.nn.Module): The input PyTorch nn.Module to be optimized. tracing_inputs (Any): Example inputs used for tracing the model graph. calibration_inputs (Any): A representative dataset or iterable of inputs used for calibration. quantization_settings (Optional[QuantizationSettings]): Global quantization settings. layer_quantization_settings (Optional[Dict[str, LayerQuantizationSettings]]): Layer-specific quantization settings. pruning_settings (Optional[PruningSettings]): Global pruning settings. layer_pruning_settings (Optional[Dict[str, LayerQuantizationSettings]]): Layer-specific pruning settings. lora_settings (Optional[LoraSettings]): LoRA configuration settings. is_model_pretrained (bool): Flag indicating if the input model has pretrained weights. Default:
True
. discard_input_model (bool): If True, the original PyTorch model might be discarded after initialization. Default:True
. huggingface_config (Optional[dict]): Optional Hugging Face model configuration dictionary. is_dry_run (bool): If True, performs initialization steps without optimizing the model. Default:False
. **kwargs: Additional keyword arguments passed to the internal initializer.Returns:
ClikaModule
: self
clika_serialize(self) ‑> bytes
Serializes the current state of the
ClikaModule
(including optimized model, settings, etc.) into bytes.Returns: bytes: The serialized representation of the
ClikaModule
.
forward(self, *args, **kwargs) ‑> Any
Executes the main forward pass of the optimized CLIKA model. Handles input packing and calls the forward method of the internal CLIKA model representation.
Args: *args: Positional arguments for the forward pass. **kwargs: Keyword arguments for the forward pass.
Returns: Any: The output(s) of the optimized model.
get_deployment_framework_name(self) ‑> Optional[str]
Gets the name of the deployment framework specified during initialization.
Returns: Optional[str]: The name of the target deployment framework (e.g., 'trt', 'ov', 'ort') as a string, or None if not set.
get_observed_input_shapes(self) ‑> dict
Retrieves the shapes observed for each model input during tracing/calibration.
Returns: dict: A dictionary where keys are input names (str) and values are their observed shapes (e.g., tuple of ints).
to(self, *args, **kwargs) ‑> clika_ace.functional.functional_api.ClikaModule
Moves and/or casts the parameters and buffers. See
torch.nn.Module.to
.Args: *args: Positional arguments passed to
torch.nn.Module.to
. **kwargs: Keyword arguments passed totorch.nn.Module.to
.Returns:
ClikaModule
: self
train(self, mode: bool = True) ‑> clika_ace.functional.functional_api.ClikaModule
Sets the module in training mode. See
torch.nn.Module.train
.Args: mode (bool): whether to set training mode (
True
) or evaluation mode (False
). Default:True
.Returns:
ClikaModule
: self
zero_grad(self, set_to_none: bool = True) ‑> None
Sets gradients of all model parameters to zero. See
torch.nn.Module.zero_grad
.Args: set_to_none (bool): instead of setting to zero, set the grads to None. Default:
True
.Returns: None