serialization
serialization
¶
Save and load compressed models with metadata.
save_compressed_model
¶
save_compressed_model(converted_model, example_inputs, save_directory, input_keys, output_keys, normalizer, training_checkpoint_path, quantization_config, quantization_workflow, model_filename=value, normalizer_filename=value, artifact_format=value, backend_name=value, model_bytes=None, denoising_thresholds=None, pt2e_backend_config=None)
Save compressed model artifact with normalizer and metadata.
Saves the deployment artifact, normalizer, quantization config, training config, optional tokenizer files, and compression metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
converted_model
|
Module | None
|
The converted model, used for Torch Export artifacts. |
required |
example_inputs
|
tuple[Tensor, ...]
|
Example input tensors for torch.export. |
required |
save_directory
|
str
|
Directory to save into (created if needed). |
required |
input_keys
|
list[str]
|
Sorted input (observation) key ordering. |
required |
output_keys
|
list[str]
|
Sorted output (action) key ordering. |
required |
normalizer
|
LinearNormalizer
|
The policy's normalizer module. |
required |
training_checkpoint_path
|
str
|
Path to the original training checkpoint directory used as the source for compression. |
required |
quantization_config
|
Any
|
The QuantizationConfig used for quantization. |
required |
quantization_workflow
|
str
|
The workflow used (QuantizationWorkflow value). |
required |
model_filename
|
str
|
Filename for the saved deployment artifact. |
value
|
normalizer_filename
|
str
|
Filename for the saved normalizer state. |
value
|
artifact_format
|
str
|
Serialized artifact format identifier. |
value
|
backend_name
|
str
|
Serialized deployment backend identifier. |
value
|
model_bytes
|
bytes | None
|
Optional pre-lowered artifact bytes, used for .pte. |
None
|
denoising_thresholds
|
dict[str, float] | None
|
Per-action-key denoising thresholds from the source policy, persisted so compressed deployments zero small deltas exactly like the float runtime. |
None
|
pt2e_backend_config
|
dict[str, Any] | None
|
Instantiable config node of the PT2E quantizer backend, persisted so inference can rebuild the backend without depending on the full compressor config schema. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the save directory. |
Source code in src/versatil/post_training_compression/serialization.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
load_compression_metadata
¶
Load compression metadata from a checkpoint directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata_path
|
str
|
Path to compression_metadata.json. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dict with runtime metadata. |