cjd_flows.export¶
ONNX export of CJD flows.
to_onnx() wraps the flow in a tiny stateless nn.Module for one of
four computations and exports it:
mode |
input |
output |
computation |
|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sampling is exported as a deterministic graph taking the latent z as
input (no RNG inside the graph); draw z with flow.base.sample.
Conditional flows (context_dim > 0) get a second input context
unless with_context=False (then flow.default_context is baked in).
The legacy TorchScript exporter (dynamo=False) is used if available
(it needs only onnx); otherwise the dynamo exporter (needs onnxscript).
- cjd_flows.export.export_module(flow, mode='log_prob', with_context=None, freeze_linear=False)[source]¶
The wrapper
nn.Modulethatto_onnx()exports (useful for other exporters).
- cjd_flows.export.to_onnx(flow, path, mode='log_prob', batch_size=1, dynamic_batch=True, opset=None, with_context=None, example=None, dynamo=None, freeze_linear=True)[source]¶
Exports
flowto ONNX.- Parameters:
mode (
str) –"log_prob","sample","forward"or"inverse"(see module doc).batch_size (
int) – batch size of the example input used for tracing.dynamic_batch (
bool) – make the batch dimension symbolic.opset (
Optional[int]) – ONNX opset (default 17 for the legacy exporter, exporter default otherwise).with_context (
Optional[bool]) – add acontextinput for conditional flows (default:Trueiffflow.context_dim > 0).example (
Optional[Tensor]) – optional example input (shape(B, *event_shape), or(B, *latent_shape)for"sample"/"inverse").dynamo (
Optional[bool]) – force the exporter (None: legacy TorchScript exporter if available, else dynamo).freeze_linear (
bool) – export the channel-linear layers (LU, orthogonal, Householder, ActNorm, …) as frozen matrices viamerge_linear()(consecutive ones are merged). Required for parametrizations that ONNX cannot express, e.g. the triangular solves ofLULinear.inverseor the Cayley map ofOrthogonalLinear.
- Return type:
- Returns:
The path of the written file.