Shortcuts

Function torch::jit::compile

Function Documentation

std::shared_ptr<script::Module> torch::jit::compile(const std::string &source)

Compiles script code into an executable graph.

Takes a string containing functions in script syntax and compiles them into a module (graph). The returned module provides a run_method function that may be used to invoke the compiled functions.

For example:

auto module = torch::jit::compile(R"JIT(
  def relu_script(a, b):
    return torch.relu(a + b)
  def test_while(a, i):
    while i < 10:
      a += a
      i += 1
    return a
)JIT");
IValue output = module->run_method("relu_script", a, b);

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources