Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:LaurentMazare Tch rs JIT Forward Pass

From Leeroopedia


Knowledge Sources
Domains Model_Inference, Interoperability
Last Updated 2026-02-08 14:00 GMT

Overview

Execution of a TorchScript model's forward method with tensor or IValue inputs, returning model predictions.

Description

JIT forward pass executes the loaded TorchScript model's forward method by passing input data through the preserved computation graph. Two variants exist: forward_ts accepts a slice of Tensor inputs (suitable for standard models), while forward_is accepts IValue inputs (for models with complex I/O types like tuples or dictionaries). The CModule also implements the Module trait, enabling use with Tensor::apply for single-tensor input models.

Usage

Use forward_ts for models with simple tensor inputs. Use forward_is for models that expect or return non-tensor types (tuples, lists, dicts). For single-input models, Tensor::apply works via the Module trait implementation.

Theoretical Basis

CModule Forward Variants:
  forward_ts(&[Tensor]) → Result<Tensor>     — For tensor-only I/O
  forward_is(&[IValue]) → Result<IValue>      — For complex I/O types
  Module::forward(&Tensor) → Tensor           — For single tensor input

IValue types: Tensor, Tuple, List, Dict, Int, Double, String, Bool, None

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment