[feat]: dispatch trusted graph artifacts with native fallback - #21
Merged
Conversation
Run a packaged optimization artifact in place of a repeated block's forward when, and only when, it provably matches -- otherwise run natively. Dispatch attaches to the same model-independent structure capture uses: children of an nn.ModuleList that share a class. No Wan-, LTX-, Cosmos- or Kandinsky-specific conditional exists anywhere in this path. Per stack and per observed input signature it runs the first call natively (which reveals the output signature), recomputes the module's graph fingerprint through the capture module so the value matches what the producer recorded, then selects a bundle whose fingerprint, tensor signatures and declared environment all match. The entry point is called as candidate(module, *args, **kwargs). Trust: executable code is loaded only from FASTVIDEO_OPTIMIZATION_ARTIFACT_DIR, every declared file is re-hashed immediately before import, undeclared files in a bundle are a hard rejection, and bundles are imported under a private module namespace rather than sys.path. Fallback: a missing match, an unloadable bundle, an untraceable module or an exception from the candidate falls back to native execution and records a structured reason; a candidate that raised is demoted, not retried. The optional diagnostics report is metadata only. With FASTVIDEO_OPTIMIZATION_ARTIFACT_DIR unset nothing is wrapped at all -- no forward is patched, no graph is traced, no artifact code is read. Tests: 28 new CPU tests with fake kernels and fake modules; 60 passed across the optimization suites. Verified end to end against a bundle packaged by MotionKernel's packager. Note: the pre-commit mypy hook fails with "FastVideo-v1-dispatch is not a valid Python package name" -- that is the checkout directory name and reproduces on untouched files. yapf, ruff and codespell pass.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fork-only — not for upstream. Stacked on
agent/graph-executable-ir.Runs a packaged optimization artifact in place of a repeated block's forward when — and only when — it provably matches. Otherwise the model runs natively.
Consumer half of
aryan5v/motionkernel#11, which owns the manifest schema.No model-specific code
Dispatch attaches to the same model-independent structure capture uses: children of an
nn.ModuleListthat share a class. There is no Wan-, LTX-, Cosmos- or Kandinsky-specific conditional anywhere in this path. A new model is supported by publishing an artifact, never by editing code.Per stack and per observed input signature:
The entry point is called as
candidate(module, *args, **kwargs). Passing the module is what lets one artifact serve every block in a stack — the kernel reads the parameters it needs from the module it was handed.Trust
FASTVIDEO_OPTIMIZATION_ARTIFACT_DIR, and only from bundles that resolve inside it.fastvideo._artifacts.*name;sys.pathis never modified.Fallback
A missing match, a bad manifest, a tampered file, an untraceable module, a failed import or an exception raised by the candidate all fall back to native execution with a structured reason (
no_artifact_for_input_signature,no_compatible_artifact,graph_identity_unavailable:*,artifact_load_failed:*,candidate_runtime_error:*, …). A candidate that raised once is demoted, not retried thousands of times.Zero effect when disabled
With
FASTVIDEO_OPTIMIZATION_ARTIFACT_DIRunset,attach_graph_dispatchreturnsNone: no forward is patched, no graph is traced, no artifact code is read. A test asserts no instance attribute shadows the class method and that outputs are identical.Diagnostics
Optional structured report (
FASTVIDEO_OPTIMIZATION_ARTIFACT_DIAGNOSTICS) recording each scope, shape key, decision reason, artifact id, rejection codes and call counts, plus registry and runtime identity. Metadata only — a test asserts no tensor- or prompt-shaped content appears in it.Testing
fastvideo/tests/optimization/test_dispatch.py) using fake kernels and fake modules only. They cover the exit criteria directly: compatible artifact selected; fingerprint, dtype, shape, output-signature, architecture, torch/CUDA/Triton version, execution-mode and distributed-mode mismatches rejected; tampered kernel rejected before import; candidate exception falls back to native output; no artifact directory behaves exactly like current FastVideo.fastvideo/tests/optimization/andtests/local_tests/optimizations/.Review notes
fastvideo/optimization/fx_capture.pyis deliberately untouched. The helpers dispatch needs are re-exported through a newidentity.py; importing them there rather than duplicating them keeps the runtime fingerprint from silently diverging from the exported one. (Running the yapf hook againstfx_capture.pyreformats 269 unrelated lines, so this also keeps the diff reviewable.)mypyhook fails withFastVideo-v1-dispatch is not a valid Python package name. That is the checkout directory name and reproduces on untouched files such asfastvideo/logger.py. yapf, ruff and codespell pass.Greptile Summary
Adds a generic artifact dispatch layer that lets packaged optimization kernels replace a model block's
forwardcall without any model-specific code. WhenFASTVIDEO_OPTIMIZATION_ARTIFACT_DIRis unset the feature is completely inert.fastvideo/optimization/artifact.py— new: manifest parsing, SHA-256 file verification,ArtifactRegistry,RuntimeProfile,check_compatibility, andload_entry_pointwith path-confinement checks.fastvideo/optimization/dispatch.py— new:GraphDispatchSessionthat wraps repeated block stacks, decides once per (scope, shape) key, demotes failed candidates permanently, and writes structured diagnostics.fastvideo/optimization/fx_capture.py— adds four thin public wrappers soidentity.pycan re-use the canonical fingerprint implementation without importing private symbols.fastvideo/pipelines/composed_pipeline_base.py— wiresattach_graph_dispatch/detach_graph_dispatchinto the pipeline setup andclosepath.Confidence Score: 5/5
Safe to merge. With FASTVIDEO_OPTIMIZATION_ARTIFACT_DIR unset the change is completely inert, and every fallback path returns native execution without propagating exceptions to the caller.
The dispatch path wraps every failure in broad exception handlers and falls back to native execution. Hash verification runs both at registry build time and immediately before exec_module, path confinement is enforced with resolve/strict=True, and undeclared files in a bundle cause a hard rejection. The only issues found are minor manifest-parsing edge cases well outside normal MotionKernel producer output.
Files Needing Attention: No files require special attention. The security-sensitive load_entry_point path in artifact.py is well-hardened.
Important Files Changed
Reviews (2): Last reviewed commit: "[bugfix]: harden generic artifact dispat..." | Re-trigger Greptile