mpcompress.utils.debug
debug_sequential
debug_sequential(sequential: Sequential, x: Tensor, name: str = 'Sequential')
Debug a Sequential layer by printing weight hashes and output hashes for each sub-layer.
This function processes the input through each layer in the Sequential module, printing detailed information about inputs, weights, and outputs at each step. Useful for debugging and verifying layer-by-layer transformations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sequential
|
|
The Sequential layer to debug. |
required |
x
|
|
Input tensor to pass through the Sequential layer. |
required |
name
|
|
Name of the Sequential layer for identification in output. |
'Sequential'
|
extract_shapes
extract_shapes(nested_structure)
Extract shape information from nested data structures.
Recursively processes nested structures (tensors, arrays, dicts, lists, tuples) and returns a structure with the same nesting but containing shape information instead of the actual data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nested_structure
|
|
A nested structure that may contain torch.Tensor, np.ndarray, bytes, dict, list, tuple, or other types. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
nested_structure |
|
A structure with the same nesting as the input. |
tensor_hash
tensor_hash(x)
Compute SHA256 hash of a tensor or numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
|
A torch.Tensor or np.ndarray to compute hash for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
hash |
|
A hexadecimal string representing the SHA256 hash of the tensor/array data. |
Raises:
| Type | Description |
|---|---|
|
If the input type is not torch.Tensor or np.ndarray. |