LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
lbann_library.hpp
Go to the documentation of this file.
1 // Copyright (c) 2014-2023, Lawrence Livermore National Security, LLC.
3 // Produced at the Lawrence Livermore National Laboratory.
4 // Written by the LBANN Research Team (B. Van Essen, et al.) listed in
5 // the CONTRIBUTORS file. <lbann-dev@llnl.gov>
6 //
7 // LLNL-CODE-697807.
8 // All rights reserved.
9 //
10 // This file is part of LBANN: Livermore Big Artificial Neural Network
11 // Toolkit. For details, see http://software.llnl.gov/LBANN or
12 // https://github.com/LLNL/LBANN.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "Licensee"); you
15 // may not use this file except in compliance with the License. You may
16 // obtain a copy of the License at:
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
23 // implied. See the License for the specific language governing
24 // permissions and limitations under the license.
26 
27 #ifndef LBANN_LIBRARY_HPP
28 #define LBANN_LIBRARY_HPP
29 
31 #include "lbann/models/model.hpp"
33 
34 namespace lbann {
35 
37 
46 std::unique_ptr<model> load_inference_model(lbann_comm* lc,
47  std::string cp_dir,
48  int mbs,
49  std::vector<int> input_dims,
50  std::vector<int> output_dims);
51 
58 template <typename DataT,
59  El::Dist CDist,
60  El::Dist RDist,
61  El::DistWrap DistView,
63 El::Matrix<int, El::Device::CPU>
65  El::DistMatrix<DataT, CDist, RDist, DistView, Device> const& samples,
66  size_t mbs)
67 {
68  auto inf_alg = batch_functional_inference_algorithm();
69  return inf_alg.infer(model, samples, mbs);
70 }
71 
73 
74 // The constructed trainer has global scope. This returns a reference
75 // to this global trainer.
77  lbann_data::Trainer* pb_trainer,
78  lbann_data::LbannPB& pb);
79 
80 std::unique_ptr<thread_pool> construct_io_thread_pool(lbann_comm* comm,
81  bool serialized_io);
82 
83 std::unique_ptr<model> build_model_from_prototext(
84  int argc,
85  char** argv,
86  const lbann_data::Trainer* pb_trainer,
87  lbann_data::LbannPB& pb,
88  lbann_comm* comm,
89  thread_pool& io_thread_pool,
90  std::vector<std::shared_ptr<callback_base>>& shared_callbacks);
91 
93  int io_threads_per_process,
94  int io_threads_offset);
95 
96 } // namespace lbann
97 
98 #endif // LBANN_LIBRARY_HPP
std::unique_ptr< model > load_inference_model(lbann_comm *lc, std::string cp_dir, int mbs, std::vector< int > input_dims, std::vector< int > output_dims)
Loads a trained model from checkpoint for inference only.
constexpr El::Device Device
El::Matrix< int, El::Device::CPU > infer(observer_ptr< model > model, El::DistMatrix< DataT, CDist, RDist, DistView, Device > const &samples, size_t mbs)
Creates execution algorithm and infers on samples using a model.
const int lbann_default_random_seed
Abstract base class for neural network models.
Definition: model.hpp:83
std::unique_ptr< model > build_model_from_prototext(int argc, char **argv, const lbann_data::Trainer *pb_trainer, lbann_data::LbannPB &pb, lbann_comm *comm, thread_pool &io_thread_pool, std::vector< std::shared_ptr< callback_base >> &shared_callbacks)
typename std::add_pointer< T >::type observer_ptr
Creating an observer_ptr to complement the unique_ptr and shared_ptr.
Definition: base.hpp:54
User-facing class that represents a set of compute resources.
Definition: trainer.hpp:60
std::unique_ptr< thread_pool > construct_io_thread_pool(lbann_comm *comm, bool serialized_io)
void print_lbann_configuration(lbann_comm *comm, int io_threads_per_process, int io_threads_offset)
trainer & construct_trainer(lbann_comm *comm, lbann_data::Trainer *pb_trainer, lbann_data::LbannPB &pb)
::distconv::tensor::Distribution Dist
int allocate_trainer_resources(lbann_comm *comm)