RAII guard forcing libtorch's default scalar type to Float64 for its lifetime, restoring the previous default on destruction.
More...
RAII guard forcing libtorch's default scalar type to Float64 for its lifetime, restoring the previous default on destruction.
MOOSE gathers and produces double (Float64) data, so every NEML2 model it drives must evaluate in Float64. A NEML2 model's working dtype is inferred from its first floating-point parameter/buffer and otherwise falls back to libtorch's default (Float32) – so a parameter-less eager model would default to Float32 and reject MOOSE's double inputs. Wrapping model construction and evaluation in this guard makes that fallback (and any default-dtype-dependent tensor created while evaluating) resolve to Float64. Save/restore rather than set-once because the default is process-global (shared with the embedded Python interpreter) and we must not disturb it outside NEML2.
Definition at line 248 of file NEML2Utils.h.