API Documentation#
Module contents#
Python package to make AI models deployment-ready for any hardware.
- class embedl_deploy.Trace(value)[source]#
Bases:
EnumTracing method used to produce the graph.
- EXPORT = 'export'#
- NONE = 'none'#
- SYMBOLIC = 'symbolic'#
- class embedl_deploy.TransformationPlan(model: GraphModule, matches: dict[str, dict[str, ~embedl_deploy._internal.core.patterns.main.PatternMatch]]=<factory>)[source]#
Bases:
objectEditable transformation plan.
Returned by
get_transformation_plan(). Thematchesdict mapsinput_node_name → pattern_class_name → PatternMatch. Togglematch.apply = Falseto skip specific matches before callingapply_transformation_plan().- matches: dict[str, dict[str, PatternMatch]]#
Nested dict of discovered matches, keyed by the last matched node’s name and the pattern class name.
- model: GraphModule#
The graph (not yet modified by replacements).
- class embedl_deploy.TransformationResult(model: GraphModule, report: TransformationReport, matches: list[PatternMatch])[source]#
Bases:
objectResult of applying a transformation plan.
Returned by
apply_transformation_plan().- matches: list[PatternMatch]#
The actual
PatternMatchobjects that were applied.
- model: GraphModule#
The transformed model with fused / quantized modules.
- report: TransformationReport#
Summary of what was applied and what was skipped.
- embedl_deploy.apply_transformation_plan(plan: TransformationPlan) TransformationResult[source]#
Apply the enabled matches from plan.
Only matches with
apply=Trueare applied viareplace(). The plan’s model is modified in place. After replacement, dead code and orphaned submodules are removed, the graph is linted and recompiled, and shape metadata is re-propagated when available. The model’s training state is preserved.- Parameters:
plan – The plan to apply (from
get_transformation_plan()).- Returns:
A
TransformationResultcontainingmodel(transformed),report(summary), andmatches(applied matches).- Raises:
ValueError – If any nodes are included in more than one enabled pattern.
Example:
result = apply_transformation_plan(plan) print(result.report) torch.onnx.export(result.model, x, "deployed.onnx")
- embedl_deploy.get_transformation_plan(graph_module: GraphModule, patterns: Sequence[type[Pattern]]) TransformationPlan[source]#
Find all non-overlapping tree-based pattern matches.
Each pattern’s
match()must returnPatternMatchobjects with a populatedtree_match. Overlapping matches are resolved by marking later overlaps asapply=False.Returns a
TransformationPlanthat can be inspected and edited before callingapply_transformation_plan().- Parameters:
graph_module – The traced graph module to analyze.
patterns – Patterns to search for. Order matters: patterns are matched in sequence, and earlier matches claim nodes first. Supply longest (most specific) patterns first to ensure they take priority over shorter ones when sub-graphs overlap.
- Returns:
A
TransformationPlancontaining graph_module andmatches(a nested dict of discovered pattern matches).
Example:
from embedl_deploy import get_transformation_plan, prepare_graph from embedl_deploy.backend import get_backend graph_module = prepare_graph(model, args) plan = get_transformation_plan( graph_module, patterns=get_backend().fusion_patterns ) for node, pats in plan.matches.items(): for name, match in pats.items(): print(f"{node}: {name} apply={match.apply}")
- embedl_deploy.prepare_graph(model: Module | GraphModule, args: tuple[Any, ...], *, trace: Trace = Trace.EXPORT) GraphModule[source]#
Trace, deep-copy, and propagate shapes.
Produces a
GraphModuleready for pattern matching. The original model is deep-copied and never modified.- Parameters:
model – The model to prepare. A
GraphModulemay be re-traced (e.g. to apply recomposition viaTrace.EXPORT) or used as-is withTrace.NONE.args – Example inputs for tracing and shape propagation.
trace – Tracing method.
Trace.EXPORT(default) usestorch.export.export()followed by recomposition;Trace.SYMBOLICusessymbolic_trace();Trace.NONEskips tracing (requires aGraphModule).
- Returns:
A deep-copied
GraphModulewith shape metadata.
- embedl_deploy.transform(model: Module | GraphModule, args: tuple[Any, ...], patterns: Sequence[type[Pattern]] | None = None, *, trace: Trace = Trace.EXPORT) TransformationResult[source]#
Apply pattern transformations to model in one step.
Conversion patterns are applied iteratively until no new matches are found, then fusion patterns are matched and applied in a single pass. Recomposition is handled automatically during tracing (see
prepare_graph()). The original model is deep-copied and never modified.- Parameters:
model – The model to transform. A
GraphModulemay be re-traced or used as-is depending ontrace.args – Example inputs for tracing.
patterns – Patterns to match and apply. When
None(the default), the active backend’sconversion_patternsandfusion_patternsare used. Order matters: patterns are matched in sequence, and earlier matches claim nodes first. Supply longest (most specific) patterns first to ensure they take priority over shorter ones when sub-graphs overlap.trace – Tracing method.
Trace.EXPORT(default) usestorch.export.export()followed by recomposition;Trace.SYMBOLICusessymbolic_trace();Trace.NONEskips tracing (requires aGraphModule).
- Returns:
A
TransformationResultcontainingmodel(transformed),report(summary), andmatches(applied matches). The report and matches reflect the fusion pass only – conversion matches become stale after fusion rewrites the graph, so only the final pass is reported. Useget_transformation_plan()andapply_transformation_plan()individually when per-phase reporting is needed.
Example:
from embedl_deploy import transform result = transform(model, args) deployable_model = result.model
Subpackages#
embedl_deploy.axelerapackageembedl_deploy.backendpackageembedl_deploy.latticepackageembedl_deploy.lattice.modulespackageembedl_deploy.lattice.patternspackageFlattenToReshapePatternLatticeC2fChunkPatternLatticeCBSRAdvancedPatternLatticeCBSRPatternLatticeConv2dAdvancedPatternLatticeConv2dPatternLatticeGELUToReLUPatternLatticeGlobalAvgPoolPatternLatticeLeakyReLUPatternLatticeMaxPool2dPatternLatticeReLU6ToReLUPatternLatticeSPPFMaxPoolAdvancedPatternLatticeSPPFMaxPoolPatternLatticeSiLUToReLUPatternLatticeStride2ConvBnReLUPattern
- Pattern lists
embedl_deploy.quantizepackageembedl_deploy.tensorrtpackageembedl_deploy.tensorrt.modulespackageembedl_deploy.tensorrt.patternspackageActAddPatternAdaptiveAvgPoolPatternConvBNActPatternConvBNAddActPatternConvBNPatternDecomposeMultiheadAttentionPatternFlattenLinearToConv1x1PatternLayerNormPatternLinearActPatternLinearPatternMHAInProjectionPatternRemoveAssertPatternRemoveIdentityAdaptiveAvgPoolPatternRemoveIdentityPatternScaledDotProductAttentionPatternStemConvBNActMaxPoolPattern
- Pattern lists
embedl_deploy.versionpackageembedl_deploy.vitispackage