memory
shrinkai.profiler.memory
Functions:
| Name | Description |
|---|---|
count_parameters |
Counts total, trainable, and non-trainable parameters. |
estimate_model_size_mb |
Estimates serialized state dictionary size on disk in Megabytes (MB). |
get_device_memory_mb |
Returns the currently allocated memory on the specified hardware accelerator. |
get_process_ram_mb |
Returns current host RAM consumption of the running Python process. |
Functions:
count_parameters
Counts total, trainable, and non-trainable parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
PyTorch model. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
dict[str, int]: Parameter count breakdown. |
Source code in src/shrinkai/profiler/memory.py
estimate_model_size_mb
Estimates serialized state dictionary size on disk in Megabytes (MB).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
PyTorch model. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Estimated file size in MB. |
Source code in src/shrinkai/profiler/memory.py
get_device_memory_mb
Returns the currently allocated memory on the specified hardware accelerator.
This is crucial for edge AI profiling, as VRAM is often the primary bottleneck.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | str
|
Computing device ('auto', 'cuda', 'mps', 'cpu', or torch.device). |
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Allocated accelerator memory in MB. Returns 0.0 for CPU
(use |
Source code in src/shrinkai/profiler/memory.py
get_process_ram_mb
Returns current host RAM consumption of the running Python process.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Resident memory in MB. |