Class NoGradGuard

java.lang.Object
smile.deep.tensor.NoGradGuard
All Implemented Interfaces:
AutoCloseable

public class NoGradGuard extends Object implements AutoCloseable
A RAII-style guard that disables gradient calculation for the duration of its lifetime. Use it with try-with-resources:
try (var guard = Tensor.noGradGuard()) {
    // inference code; no autograd graph is built
}
The guard is thread-local; it does not affect computation in other threads.
  • Method Details