activation_trace
¶
Zero-overhead-when-off activation trace mode for FastVideo pipelines.
Enable by setting FASTVIDEO_TRACE_ACTIVATIONS=1. When off, this module adds zero overhead — no hooks are registered, no branches exist in the production forward path. When on, registers forward hooks on modules whose name matches FASTVIDEO_TRACE_LAYERS, computes the requested stats (FASTVIDEO_TRACE_STATS) on each output tensor, and writes JSONL records to FASTVIDEO_TRACE_OUTPUT.
Useful for parity debugging across model ports — log on both the FastVideo path and the upstream reference, diff the two JSONL files to find the first divergent layer.
Example:
FASTVIDEO_TRACE_ACTIVATIONS=1 FASTVIDEO_TRACE_LAYERS="^block\.layers\.[0-9]+$" FASTVIDEO_TRACE_STATS="abs_mean,max,shape" FASTVIDEO_TRACE_OUTPUT="/tmp/fv_trace.jsonl" python examples/inference/basic/basic_magi_human.py
Classes¶
fastvideo.hooks.activation_trace.ActivationStatHook
¶
ActivationStatHook(module_name: str, stats: list[tuple[str, Callable[[Tensor], Any]]], sink: JsonlSink, step_filter: set[int] | None)
Bases: ForwardHook
Forward hook that emits per-tensor stats to a JSONL sink.
Source code in fastvideo/hooks/activation_trace.py
fastvideo.hooks.activation_trace.JsonlSink
¶
JsonlSink(path: Path)
Buffered JSONL writer with thread-safe append.
Source code in fastvideo/hooks/activation_trace.py
Functions¶
fastvideo.hooks.activation_trace.attach_activation_trace
¶
Attach activation-stat hooks to model. Returns None if trace is off.
Source code in fastvideo/hooks/activation_trace.py
fastvideo.hooks.activation_trace.trace_step
¶
Context manager that sets the current denoise step for trace records.