Repository navigation
[circle] Optimizing circe export passes by caching - #1103
Merged
Merged
Conversation
dvsav
reviewed
Nov 3, 2026
|
|
||
| def get_constant_from_tensor( | ||
| node: Union[torch.fx.Node, float], ep: ExportedProgram | ||
| node: Union[torch.fx.Node, float], ep: ExportedProgram, _cache=None |
Contributor
There was a problem hiding this comment.
_cache is a public, positional third parameter of the exported function with no type annotation (_cache=None) in an otherwise typed module. The underscore convention on a positional argument is weak protection.
Contributor
(Optional)
|
Contributor
(Optional) The same O(N)-copy antipattern survives in code the O1 rules call per element
|
This commit optimizes circe export passes by caching Co-Authored-By: Cline TICO-DCO-1.0-Signed-off-by: Evgenii Maltsev <e.maltsev@samsung.com>
Torrero
force-pushed
the
circle_pass_optimization
branch
from
November 5, 2026 19:08
1c15aa3 to
0d6b331
Compare
Contributor
Author
|
@dvsav Thank you for your comments, I fixed it |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Exporting large quantized models to Circle (e.g. Qwen3-VL-4B, whose vision subgraph unrolls attention per chunk×head×block into ~10^5–10^6 operators) takes hours of single-threaded CPU with no artifact.
py-spy profiling showed ~93% of export time is spent in TICO's own pass machinery, and ~7% for torch.export:
Root causes
CircleGraph._operator()rebuiltas_list(subgraph.operators)— an O(N) flatbuffer→list copy — on every accessor call, making every graph traversal O(N²).operator_is_live()ran a full-graph BFS (backward_operators) per operator per rule match → O(N³) in the rules engine.get_constant_from_tensor()re-walked scale/zero-point constant chains without memoization, once per fake-quantize node.Changes
tico/circle/graph.py_operators_list/_tensors_listonce at construction (instances are revision-pinned immutable snapshots — the session rebuilds them on any subgraph mutation, so caches cannot go stale).operator_inputs/operator_outputs.live_operators(): one BFS per graph, cached asfrozenset(immutable — callers cannot corrupt the shared cache).tico/circle/passes/optimization/_pattern_utils.pyoperator_is_live()uses the cachedlive_operators().tico/passes/decompose_fake_quantize_tensor_qparams.pyget_constant_from_tensor()with a per-pass-run cache keyed by node name.Correctness
tico-circle verifypasses on all produced artifacts.CircleOptimizationSession.graph()); the FX-pass cache lives exactly onecall()and reads only immutable constant chains.Performance (quantized Qwen3-VL-4B export)
Co-Authored-By: Cline SR
TICO-DCO-1.0-Signed-off-by: Evgenii Maltsev e.maltsev@samsung.com