https://mooseframework.inl.gov
Loading...
Searching...
No Matches
LibtorchModel.h
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9#if 0 // NEML2 v2->v3 migration: DEFERRED (FEM/discretization/typed-tensor path has no v3 C++
10 // equivalent yet)
11
12#pragma once
13
14#ifdef NEML2_ENABLED
15
16// libtorch headers
17#include <torch/script.h>
18
19// neml2 headers
20#include "neml2/models/Model.h"
21
22// moose headers
23#include "DataFileUtils.h"
24
25namespace neml2
26{
27
33class LibtorchModel : public Model
34{
35public:
36 static OptionSet expected_options();
37
38 LibtorchModel(const OptionSet & options);
39
44 virtual void to(const torch::TensorOptions & options) override;
45
46 virtual void request_AD() override;
47
48protected:
49 virtual void set_value(bool out, bool dout_din, bool d2out_din2) override;
50
51 // Input variable vector
52 std::vector<const Variable<Scalar> *> _inputs;
53 // Output vector
54 std::vector<Variable<Scalar> *> _outputs;
57 std::unique_ptr<torch::jit::script::Module> _surrogate;
58};
59
60}
61
62#endif
63
64#endif // NEML2 v2->v3 migration: DEFERRED
Evaluate a pretrained libtorch model in .pt format, such as a neural network.
virtual void request_AD() override
virtual void to(const torch::TensorOptions &options) override
Override the base implementation to additionally send the model loaded from torch script to different...
std::vector< const Variable< Scalar > * > _inputs
std::unique_ptr< torch::jit::script::Module > _surrogate
We need to use a pointer here because forward is not const qualified.
Moose::DataFileUtils::Path _file_path
virtual void set_value(bool out, bool dout_din, bool d2out_din2) override
static OptionSet expected_options()
std::vector< Variable< Scalar > * > _outputs
Representation of a data file path.