Skip to content

jit_inline

torch_to_nnef.torch_graph.jit_inline

Selective inlining of unresolvable JIT submodule calls.

torch_to_nnef's recursive parser identifies the class behind a prim::CallMethod via importlib.import_module(qualname.module_path) and isinstance(submod, ref_cls). JIT artifacts shipped without their training source (e.g. Silero-VAD's silero_vad.jit) carry qualified names like __torch__.vad.model.vad_annotator.SileroVadBlock that fail to import.

inline_unresolvable_submodules(graph, model) walks the JIT graph and inlines exactly those calls in place, leaving importable torch.nn.* calls intact so existing module-level extractors (LSTM, GRU, RNN, ...) still fire.

Companion to strip_assertion_ifs in this package: a typical JIT-only preprocessing chain is inline_unresolvable_submodules -> _jit_pass_dce -> strip_assertion_ifs.

inline_unresolvable_submodules

inline_unresolvable_submodules(graph: 'torch._C.Graph', model: nn.Module, max_passes: int = 1024) -> int

Inline every prim::CallMethod whose target class is not importable.

Iterates until fixed point: an inlined body may itself contain further CallMethods that also need inlining. max_passes bounds the loop against pathological non-termination on weirdly structured graphs; raise it for unusually deep nested inlines, lower it to fail fast when debugging.

Returns the count of inlined calls.