PyTorch normally runs computations eagerly, which makes them easy to debug. Compilation is an optional attempt to make repeated computations faster: `torch$compile()` accepts a function or a `Module` and returns an object intended to behave the same way, with faster forward and backward passes. It uses PyTorch’s Dynamo compiler. section 3.4.2 section 3.4.3
Compile a PyTorch function
After `library(keras3)`, `use_backend("torch")`, and `torch <- import("torch")`, define a dense computation as `dense <- torch$compile(function(inputs, W, b) { torch$nn$relu(torch$matmul(inputs, W) + b) })`. The multiplication, bias addition, and activation stay together inside the function passed to the compiler. If the computation is already packaged as a `Module` called `model`, use `compiled_model <- torch$compile(model)` instead. section 3.4.1 section 3.4.2
Treat compilation as a performance option, not a required training step. Most PyTorch code remains eager: compilation may fail for some models or produce no speedup. Keeping an eager version is useful when debugging. TensorFlow offers a comparable function-level option through `tf_function()` and `jit_compile = TRUE`. section 3.4.2 section 3.3.1






