Export¶
Quantize and export PyTorch models for DeepGate edge deployment.
Functions:
| Name | Description |
|---|---|
trace |
Trace |
export |
Lower a quantized model to a |
dg.trace
¶
trace(
model: Module,
example_inputs: Tensor | tuple[Tensor, ...],
*,
dynamic_batch: bool = True
) -> torch.fx.GraphModule
Trace model into the graph that dg.export lowers.
This is the whole export path for a logic model, which has no quantization:
A quantized model is traced by enable_quantization instead, so you do
not call this yourself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to trace. Tracing runs on the model's own device, and the traced graph comes back on that same device. |
required |
example_inputs
|
Tensor | tuple[Tensor, ...]
|
Example inputs to trace with. Pass a batch of at least
2 samples when |
required |
dynamic_batch
|
bool
|
Let the traced graph accept any batch size. A batch of 1 would otherwise be baked in as a fixed size. |
True
|
Returns:
| Type | Description |
|---|---|
GraphModule
|
The traced graph, ready for |
dg.export
¶
export(
converted: GraphModule,
*,
input_boundary: str = DType.FLOAT32,
output_boundary: str = DType.FLOAT32,
preprocess: Preprocessor | None = None
) -> dict[str, Any]
Lower a quantized model to a schema.json dict for deployment.
Write the returned dict out with json.dump and upload it to the DeepGate
platform to compile or benchmark. Any operation that cannot be lowered
raises an error rather than being silently dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
converted
|
GraphModule
|
The quantized graph from |
required |
input_boundary
|
str
|
Dtype the deployed model accepts, |
FLOAT32
|
output_boundary
|
str
|
Dtype the deployed model returns, |
FLOAT32
|
preprocess
|
Preprocessor | None
|
An audio or image pipeline to compile into the model, so
deployed inference runs the same preprocessing you trained on.
Requires the default float32 |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The schema dict. |