hooks
¶
Modules¶
fastvideo.hooks.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.
Source code in fastvideo/hooks/activation_trace.py
fastvideo.hooks.hooks
¶
Classes¶
fastvideo.hooks.hooks.ForwardHook
¶
Base class for forward hooks. Hooks are used in the way: modified_args, modified_kwargs = hook.pre_forward(module, args, kwargs) output = module.forward(modified_args, **modified_kwargs) modified_output = hook.post_forward(module, output)
Methods:¶
fastvideo.hooks.hooks.ForwardHook.on_attach
¶ fastvideo.hooks.hooks.ForwardHook.on_detach
¶Called once when the hook is detached from the module. Note: this function is not guaranteed to be called if the module is deleted before the hook is detached.
fastvideo.hooks.hooks.ForwardHook.post_forward
¶ fastvideo.hooks.hooks.ForwardHook.pre_forward
¶
fastvideo.hooks.layerwise_offload
¶
Classes¶
fastvideo.hooks.layerwise_offload.LayerwiseOffloadHook
¶
Bases: ForwardHook
A hook that enables layerwise CPU offloading during forward pass.