LBANN  0.103.0
LivermoreBigArtificialNeuralNetworkToolkit
layer.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_LAYERS_LAYER_HPP_INCLUDED
28 #define LBANN_LAYERS_LAYER_HPP_INCLUDED
29 
30 #include "lbann/base.hpp"
32 #include "lbann/utils/typename.hpp"
33 #include <string>
34 #include <vector>
35 #ifdef LBANN_HAS_ONNX
36 #include <onnx/onnx_pb.h>
37 #endif
38 
41 #define LBANN_DEFINE_LAYER_BUILDER(LAYER_NAME) \
42  template <typename TensorDataType, data_layout Layout, El::Device Device> \
43  std::unique_ptr<Layer> build_##LAYER_NAME##_layer_from_pbuf( \
44  lbann_comm*, \
45  lbann_data::Layer const&)
46 
50 #define LBANN_LAYER_DEFAULT_BUILDER(LAYER_NAME) \
51  template <typename TensorDataType, data_layout Layout, El::Device Device> \
52  std::unique_ptr<Layer> build_##LAYER_NAME##_layer_from_pbuf( \
53  lbann_comm* comm, \
54  lbann_data::Layer const&) \
55  { \
56  using LayerType = LAYER_NAME##_layer<TensorDataType, Layout, Device>; \
57  return std::make_unique<LayerType>(comm); \
58  }
59 
63 #define LBANN_LAYER_BUILDER_ETI(LAYER_NAME, T, Device) \
64  template std::unique_ptr<Layer> \
65  build_##LAYER_NAME##_layer_from_pbuf<T, \
66  ::lbann::data_layout::DATA_PARALLEL, \
67  Device>(lbann_comm*, \
68  lbann_data::Layer const&); \
69  template std::unique_ptr<Layer> \
70  build_##LAYER_NAME##_layer_from_pbuf<T, \
71  ::lbann::data_layout::MODEL_PARALLEL, \
72  Device>(lbann_comm*, \
73  lbann_data::Layer const&)
74 
75 // Forward-declare protobuf classes
76 namespace lbann_data {
77 class Layer;
78 }
79 
80 namespace lbann {
81 
82 // Forward declarations
83 class lbann_comm;
84 class description;
85 class Layer;
86 class model;
87 class lbann_summary;
88 class weights;
89 using ViewingWeightsPtr = std::weak_ptr<weights>;
90 #ifdef LBANN_HAS_DISTCONV
91 class distconv_adapter;
92 #endif // LBANN_HAS_DISTCONV
93 namespace callback {
94 class sync_layers;
95 } // namespace callback
96 class KFAC;
97 template <hydrogen::Device Device>
98 class kfac_block_fc_conv;
99 template <hydrogen::Device Device>
101 template <hydrogen::Device Device>
102 class kfac_block_bn;
103 template <hydrogen::Device Device>
104 class kfac_block_gru;
105 
125 using OwningLayerPtr = std::shared_ptr<Layer>;
133 using ViewingLayerPtr = std::weak_ptr<Layer>;
134 
137 {
139  int sample_groups = 0;
141  int sample_splits = 0;
143  int depth_groups = 0;
145  int depth_splits = 0;
147  int height_groups = 0;
149  int height_splits = 0;
151  int width_groups = 0;
153  int width_splits = 0;
155  int channel_groups = 0;
157  int channel_splits = 0;
159  int filter_groups = 0;
161  int filter_splits = 0;
163  int replications = 0;
165  bool enable_subgraph = false;
167  int sub_branch_tag = 0;
169  int sub_branch_resource_percentage = 0;
170  bool operator==(const ParallelStrategy& ps) const
171  {
172  return sample_groups == ps.sample_groups &&
173  sample_splits == ps.sample_splits &&
174  depth_groups == ps.depth_groups && depth_splits == ps.depth_splits &&
175  height_groups == ps.height_groups &&
176  height_splits == ps.height_splits &&
177  width_groups == ps.width_groups && width_splits == ps.width_splits &&
178  channel_groups == ps.channel_groups &&
179  channel_splits == ps.channel_splits &&
180  filter_groups == ps.filter_groups &&
181  filter_splits == ps.filter_splits &&
182  replications == ps.replications &&
183  sub_branch_tag == ps.sub_branch_tag &&
184  sub_branch_resource_percentage ==
186  enable_subgraph == ps.enable_subgraph;
187  }
188  bool operator!=(const ParallelStrategy& ps) const { return !(*this == ps); }
189 };
190 
191 inline std::ostream& operator<<(std::ostream& os, const ParallelStrategy& ps)
192 {
193  os << "{"
194  << "N: " << ps.sample_groups << "/" << ps.sample_splits << ", "
195  << "C: " << ps.channel_groups << "/" << ps.channel_splits << ", "
196  << "D: " << ps.depth_groups << "/" << ps.depth_splits << ", "
197  << "H: " << ps.height_groups << "/" << ps.height_splits << ", "
198  << "W: " << ps.width_groups << "/" << ps.width_splits << ", "
199  << "F: " << ps.filter_groups << "/" << ps.filter_splits << ", "
200  << "R: " << ps.replications << ", "
201  << "T: " << ps.sub_branch_tag << ", "
202  << "%: " << ps.sub_branch_resource_percentage << ", "
203  << "e: " << ps.enable_subgraph << "}";
204  return os;
205 }
206 
207 inline std::ostream& print_parallel_strategy_header(std::ostream& os)
208 {
209  os << "Axis over which DistConv can parallelize:\n"
210  << "\tSamples in the mini-batch (N)\n"
211  << "\tDepth, Height, and Width (D x H x W)\n"
212  << "\tChannel (C)\n"
213  << "\tFilters (F)\n"
214  << "\tReplications (R): Number of times the layer is replicated (for FC "
215  "layers right now)\n"
216  << "\tBranch number in the subgraph (T)\n"
217  << "\tPercentage of parent resources to be allocated to this branch (%)\n"
218  << "\tEnable subgraph for the layer (e)\n"
219  << "\nFor each of the above dimensions there are two fields:\n"
220  << "\t# Groups (G): refers to how many reduced-order tensors exist with "
221  "respect to that dimension"
222  << std::endl
223  << "\t e.g. For a kD tensor you would have a stack of G "
224  "(k-1)D tensors"
225  << std::endl
226  << "\t\t[N, C, D, H, W]" << std::endl
227  << "\t\t[2, 1, 4, 1, 1] ---" << std::endl
228  << "\t\t |" << std::endl
229  << "\t\t V" << std::endl
230  << "\t\t 4 Depth groups: [N, C, H, W]" << std::endl
231  << "\t\t [2, 1, 1, 1]" << std::endl
232  << "\t\t [2, 1, 1, 1]" << std::endl
233  << "\t\t [2, 1, 1, 1]" << std::endl
234  << "\t\t [2, 1, 1, 1]" << std::endl
235  << "\t\t[1, 1, 4, 1, 2] ---" << std::endl
236  << "\t\t |" << std::endl
237  << "\t\t V" << std::endl
238  << "\t\t 2 Sample groups: [C, D, H, W]" << std::endl
239  << "\t\t [1, 4, 1, 1]" << std::endl
240  << "\t\t [1, 4, 1, 1]" << std::endl
241  << "\n\tSplit per Dimension (S): Number of groups the dimension is split "
242  "over (i.e. split K times) (aka H2 split shape) (must divide groups "
243  "evenly).\n"
244  << std::endl;
245 
246  os << "Reporting order for the parallel strategy" << std::endl;
247  os << "{N: G/S"
248  << ", C: G/S"
249  << ", D: G/S"
250  << ", H: G/S"
251  << ", W: G/S"
252  << ", F: G/S"
253  << ", R:"
254  << ", T:"
255  << ", %:"
256  << ", e:"
257  << "}";
258  return os;
259 }
260 
262 {
263  PT2PT = 0,
264  COLL = 10,
266 };
267 
285 class Layer
286 {
287  friend class callback::sync_layers;
288  friend class KFAC;
289  template <hydrogen::Device Device>
290  friend class kfac_block_fc_conv;
291  template <hydrogen::Device Device>
293  template <hydrogen::Device Device>
294  friend class kfac_block_bn;
295  template <hydrogen::Device Device>
296  friend class kfac_block_gru;
297 
298 public:
300  Layer();
302  virtual ~Layer() = default;
303 
309  virtual Layer* copy() const = 0;
310 
312 
313 
319  void set_name(const std::string name) { m_name = name; }
321  void set_model(model* m) { m_model = m; }
322 
324 
325 
332  std::string get_name() const { return m_name; }
333 
339  model* get_model() const noexcept { return m_model; }
340 
347  virtual std::string get_type() const = 0;
348 
350  virtual std::string get_datatype_name() const = 0;
351 
353  virtual description get_description() const;
354 
361  virtual data_layout get_data_layout() const = 0;
368  virtual El::Device get_device_allocation() const = 0;
369 
373  int get_expected_num_parent_layers() const noexcept
374  {
375  return m_expected_num_parent_layers;
376  }
377 
381  int get_expected_num_child_layers() const noexcept
382  {
383  return m_expected_num_child_layers;
384  }
385 
389  virtual int get_backprop_requirements() const
390  {
392  }
393 
396  {
397  return m_parallel_strategy;
398  }
400  ParallelStrategy const& get_parallel_strategy() const noexcept
401  {
402  return m_parallel_strategy;
403  }
404 
406 
411  virtual bool can_run_inplace() const { return false; }
412 
414 #ifdef LBANN_HAS_GPU
415  bool using_gpus() const { return get_device_allocation() == El::Device::GPU; }
416 #else
417  bool using_gpus() const noexcept { return false; }
418 #endif // LBANN_HAS_GPU
419 
421 
422 
428  virtual void forward_prop() = 0;
435  void back_prop();
436 
441  bool update();
442 
450  virtual void setup(size_t max_mini_batch_size,
451  const std::vector<El::Grid*>& grids);
452 
454  virtual void check_setup();
455 
457 
459  void write_proto(lbann_data::Layer& proto) const;
460 
462 
464  // FIXME (trb 10/03/2023): The lbann_summary class should be
465  // reevaluated. This strikes me as a feature that should be moved to
466  // a callback and/or replaced by proper performance
467  // profilers/counters (e.g., Caliper). More directly: I'm not sure
468  // anyone has used the summarizer in at least 2 years and it might
469  // be time to trim that out.
470  void summarize_stats(lbann_summary& summarizer, int step);
471  virtual void summarize_matrices(lbann_summary& summarizer, int step) = 0;
472 
474  void reset_counters();
475 
477 
478 
480  // (trb 10/03/2023): unused, but accessor is used; kept for symmetry
482  {
483  subgraph_communication_method = type;
484  }
485 
486  // (trb 10/03/2023): used, keeping setter, which is unused.
488  {
489  return subgraph_communication_method;
490  }
491 
492  // (trb 10/03/2023): used
493  void set_num_spliting_groups(El::Int spliting_groups)
494  {
495  m_num_spliting_groups = spliting_groups;
496  }
497 
498  // (trb 10/03/2023): used
499  El::Int get_num_spliting_groups() const { return m_num_spliting_groups; }
500 
501  // (trb 10/03/2023): USED BUT THIS IS BAD BECAUSE m_mygrid IS NEVER SET!
502  std::shared_ptr<El::Grid> get_mygrid() const
503  {
504  LBANN_ERROR("This function should not be used.");
505  return nullptr;
506  }
507 
508  // (trb 10/03/2023): used, model.cpp
509  void reset_inter_subgrid_vc_comm(std::shared_ptr<El::mpi::Comm> mpi_comm)
510  {
511  m_interSubGridVCComm = std::move(mpi_comm);
512  }
513 
514  // (trb 10/03/2023): used
516  {
517  m_subgraph_parallelism_execution = true;
518  }
519 
520  // layer-level sub-graph parallelism execution
521  // (trb 10/03/2023): used
522  bool subgraph_parallelism_execution() const noexcept
523  {
524  return m_subgraph_parallelism_execution;
525  }
526 
527  // (trb 10/03/2023): used
528  void set_run_layer_in_subgraph() { run_layer_in_subgraph = true; }
529 
530  // (trb 10/03/2023): used
531  bool get_run_layer_in_subgraph() const noexcept
532  {
533  return run_layer_in_subgraph;
534  }
536 
537 private:
539  virtual void write_specific_proto(lbann_data::Layer& proto) const = 0;
540 
541 public:
542 #ifdef LBANN_HAS_ONNX
543 
548  virtual void fill_onnx_node(onnx::GraphProto& graph) const;
549 
550 private:
557  virtual std::string get_onnx_op_type() const;
558 #endif // LBANN_HAS_ONNX
559 
560 public:
562 
564  const Layer& get_parent_layer(size_t index = 0) const;
565  const Layer& get_child_layer(size_t index = 0) const;
566 
567  std::vector<const Layer*> get_parent_layers() const;
568  std::vector<const Layer*> get_child_layers() const;
569 
570  size_t find_parent_layer_index(const Layer& l) const;
571  size_t find_child_layer_index(const Layer& l) const;
572 
574  int get_num_parents() const noexcept { return m_parent_layers.size(); }
576  int get_num_children() const noexcept { return m_child_layers.size(); }
577 
579 
580 
587  void add_parent_layer(ViewingLayerPtr parent);
593  void add_child_layer(ViewingLayerPtr child);
594 
595  void replace_parent_layer(ViewingLayerPtr l, size_t index);
596  void replace_child_layer(ViewingLayerPtr l, size_t index);
597 
599  void clear_parent_layers() { m_parent_layers.clear(); }
601  void clear_child_layers() { m_child_layers.clear(); }
602 
603  ViewingLayerPtr get_parent_layer_pointer(size_t index) const;
604  ViewingLayerPtr get_child_layer_pointer(size_t index) const;
605 
607  virtual std::vector<ViewingLayerPtr> get_layer_pointers();
612  virtual void set_layer_pointers(std::vector<ViewingLayerPtr> layers);
613 
615 
616 
619  std::vector<ViewingWeightsPtr> get_weights_pointers() const;
621  void set_weights_pointers(std::vector<ViewingWeightsPtr> ptrs);
622 
624  void replace_weights(Layer const& other_layer);
625 
627 
628 
631  virtual const BaseDistMat& get_activations(const Layer& child) const = 0;
633  virtual const BaseDistMat& get_error_signals(const Layer& parent) const = 0;
634 
636 
637 
640  std::vector<int> get_input_dims(size_t input_index = 0) const;
642  int get_input_size(size_t input_index = 0) const;
644  std::vector<int> get_output_dims(size_t output_index = 0) const;
646  int get_output_size(size_t output_index = 0) const;
647 
649  void set_output_dims(std::vector<int> dims, size_t output_index = 0);
650 
651  El::Int infer_mini_batch_size_from_parents() const;
652  virtual El::Int current_output_mini_batch_size() const = 0;
653  virtual El::Int
654  infer_mini_batch_size_from_parents_or_default_to_current() const = 0;
655 
657 
659  lbann_comm* get_comm() const;
660 
662  int get_grid_tag() const noexcept;
664  void set_grid_tag(int tag);
665 
667 
675  void set_hint_layer(ViewingLayerPtr l);
676 
678  const Layer* get_hint_layer() const;
679 
681 
682 
684  void freeze();
685  void unfreeze();
686  bool is_frozen() const;
687 
689 
695  virtual void set_keep_error_signals(bool) = 0;
696 
702  bool runs_inplace() const { return m_runs_inplace; }
703 
705 
707  template <typename ArchiveT>
708  void serialize(ArchiveT& ar);
709 
711 
712 protected:
714  Layer(Layer&& other) = default;
716  Layer(Layer const& other);
717  Layer& operator=(Layer&& other) = default;
718  Layer& operator=(Layer const& other);
720 
722  void add_weights(ViewingWeightsPtr w)
724  {
725  m_weights.emplace_back(std::move(w));
726  }
727  size_t num_weights() const noexcept { return m_weights.size(); }
728  bool has_weights() const noexcept { return num_weights() > 0; }
729  bool has_weights(size_t idx) const noexcept
730  {
731  return ((idx < m_weights.size()) && (!m_weights[idx].expired()));
732  }
733  void set_num_weights(size_t n) { m_weights.resize(n); }
734  void set_weights(size_t idx, ViewingWeightsPtr w)
735  {
736  m_weights.at(idx) = std::move(w);
737  }
738  weights const& get_weights(size_t idx) const;
739 
740  weights& get_weights(size_t idx);
741 
742  void add_as_gradient_source();
743 
744  void remove_as_gradient_source();
746 
747  // ===========================================================
748  // Setup helper functions
749  // ===========================================================
750 
753  void setup_grid();
758  virtual void setup_pointers();
764  virtual void setup_dims();
773  virtual void setup_matrices(const std::vector<El::Grid*>& grids) = 0;
778  virtual void setup_data(size_t max_mini_batch_size){};
782  virtual void setup_gpu() {}
783 
784  // ===========================================================
785  // Forward prop step helper functions
786  // ===========================================================
787 
793  virtual void fp_setup_inputs() = 0;
798  virtual void fp_setup_outputs() = 0;
803  virtual void fp_compute() = 0;
804 
805  // ===========================================================
806  // Back prop step helper functions
807  // ===========================================================
808 
813  virtual void bp_setup_gradient_wrt_inputs() = 0;
820  virtual void bp_compute(){};
821 
822  // ===========================================================
823  // Update step helper functions
824  // ===========================================================
825 
829  virtual bool update_compute() { return true; }
830 
831  // ===========================================================
832  // Protected class members
833  // ===========================================================
834 
838  int m_expected_num_parent_layers = 1;
842  int m_expected_num_child_layers = 1;
843 
845  model* m_model = nullptr;
846 
848  bool m_frozen;
849 
860 
865  std::string m_name;
866 
872  bool m_runs_inplace = false;
873 
874  // -------------------------------------------------------
875  // Objects for sub-grid parallelism
876  // -------------------------------------------------------
878 
886  int m_grid_tag = -1;
887 
888  // -------------------------------------------------------
889  // Objects from old sub-grid parallelism implementation
890  // -------------------------------------------------------
892 
893  SubGraphCommunication subgraph_communication_method = PT2PT;
894 
895  // Model-level: Is subgraph parallelism enabled for this Model?
896  // Layer-level: Does this layer need subgraph execution (like split and sum
897  // layers) Process-level: Does this layer exist in the given process (For e.g.
898  // some layers will only run on a subset of processes defined by grid tag)
899  // Layer-level sub-graph execution
900  bool m_subgraph_parallelism_execution = false;
901  // Process-level sub-graph execution
902  bool run_layer_in_subgraph = false;
903 
905  std::unique_ptr<std::set<int>> m_subgrid_ranks;
906 
907  El::Int m_num_spliting_groups = 1;
908  std::shared_ptr<El::mpi::Comm> m_interSubGridVCComm;
909 
910 private:
912 
926  friend void attempt_move_error_signal(Layer& parent,
927  Layer const& child,
928  std::unique_ptr<BaseDistMat> signal);
929  friend void attempt_view_error_signal(Layer& parent,
930  Layer const& child,
931  const BaseDistMat& signals);
932  friend void deep_copy_error_signal(Layer& parent,
933  Layer const& child,
934  const BaseDistMat& signals);
935 
937  virtual void back_prop_impl_() = 0;
938 
945  virtual void allocate_new_gradients_() = 0;
946 
954  virtual void propagate_error_signals_to_parents_() = 0;
955 
966  virtual void clear_prev_error_signals_() = 0;
967 
977  virtual void move_or_copy_prev_error_signal_(
978  const Layer& child,
979  std::unique_ptr<El::BaseDistMatrix> signal) = 0;
980 
990  virtual void
991  view_or_copy_prev_error_signal_(const Layer& child,
992  const El::BaseDistMatrix& signal) = 0;
993 
1000  virtual void
1001  deep_copy_prev_error_signal_(const Layer& child,
1002  const El::BaseDistMatrix& signal) = 0;
1003 
1005 
1006  // ===========================================================
1007  // Private class members
1008  // ===========================================================
1009 
1011  std::vector<ViewingLayerPtr> m_parent_layers;
1013  std::vector<ViewingLayerPtr> m_child_layers;
1014 
1023  std::vector<ViewingWeightsPtr> m_weights;
1024 
1026  std::vector<std::vector<int>> m_output_dims_list;
1027 
1034 
1037 
1038 #ifdef LBANN_HAS_DISTCONV
1039 private:
1040  friend class distconv_adapter;
1041 
1042 public:
1044  bool distconv_enabled() const;
1046  virtual bool keep_original_inputs(int index) const;
1048  virtual bool keep_original_outputs(int index) const;
1051  virtual bool keep_original_gradient_wrt_inputs(int index) const;
1054  virtual bool keep_original_gradient_wrt_outputs(int index) const;
1056  virtual const distconv_adapter& get_distconv_adapter() const;
1058  virtual distconv_adapter& get_distconv_adapter();
1059 
1060 protected:
1062  virtual bool is_distconv_supported() const { return false; }
1064  void prepare_distconv();
1065  virtual void setup_distconv_adapter() = 0;
1066  std::unique_ptr<distconv_adapter>& get_distconv_adapter_ptr()
1067  {
1068  return m_dc;
1069  };
1070  const std::unique_ptr<distconv_adapter>& get_distconv_adapter_ptr() const
1071  {
1072  return m_dc;
1073  };
1074 
1075 private:
1076  mutable bool m_distconv_enabled = false;
1077  mutable bool m_distconv_enabled_set = false;
1078  std::unique_ptr<distconv_adapter> m_dc;
1079 #else
1080 public:
1082  bool distconv_enabled() const { return false; }
1083 
1084 #endif // LBANN_HAS_DISTCONV
1085 };
1086 
1087 } // namespace lbann
1088 
1089 #endif // LBANN_LAYERS_LAYER_HPP_INCLUDED
bool distconv_enabled() const
Indicate whether distconv is enabled.
Definition: layer.hpp:1082
int sub_branch_resource_percentage
Definition: layer.hpp:169
model * get_model() const noexcept
Get a reference to the model that manages this layer.
Definition: layer.hpp:339
ParallelStrategy & get_parallel_strategy() noexcept
Get the parallel strategy for the layer.
Definition: layer.hpp:395
EvalType m_fp_time
Time spent in forward propagation.
Definition: layer.hpp:851
virtual int get_backprop_requirements() const
Returns the necessary tensors for computing backpropagation.
Definition: layer.hpp:389
virtual void setup_data(size_t max_mini_batch_size)
Setup layer data. Called by the &#39;setup&#39; function. Memory is allocated for distributed matrices...
Definition: layer.hpp:778
EvalType m_update_time
Time spent in updates.
Definition: layer.hpp:859
int get_expected_num_child_layers() const noexcept
Get expected number of child layers. A negative value indicates no limit.
Definition: layer.hpp:381
std::unique_ptr< std::set< int > > m_subgrid_ranks
Definition: layer.hpp:905
#define LBANN_ERROR(...)
Definition: exception.hpp:37
std::weak_ptr< Layer > ViewingLayerPtr
Smart pointer to reference a layer object.
Definition: layer.hpp:133
bool operator==(const ParallelStrategy &ps) const
Definition: layer.hpp:170
int get_num_parents() const noexcept
Get number of parent layers.
Definition: layer.hpp:574
bool runs_inplace() const
If true, the layer will run in-place (the input and output activations point to the same tensor)...
Definition: layer.hpp:702
void clear_parent_layers()
Remove pointers to parent layers.
Definition: layer.hpp:599
void serialize(std::ostream &os, google::protobuf::Message const &msg)
Serialize the protobuf message to a stream.
Neural network tensor operation.
Definition: layer.hpp:285
Generates nicely formatted description messages.
Definition: description.hpp:49
int get_expected_num_parent_layers() const noexcept
Get expected number of parent layers. A negative value indicates no limit.
Definition: layer.hpp:373
void set_model(model *m)
Set the model that manages this layer.
Definition: layer.hpp:321
void set_num_spliting_groups(El::Int spliting_groups)
Definition: layer.hpp:493
constexpr El::Device Device
bool m_frozen
Avoid back prop if frozen.
Definition: layer.hpp:848
An implementation of the KFAC second-order optimization algorithm.
Definition: kfac.hpp:59
std::ostream & operator<<(std::ostream &os, lbann::utils::argument_parser< ErrorHandler > const &parser)
Write the parser&#39;s help string to the given ostream.
std::shared_ptr< El::mpi::Comm > m_interSubGridVCComm
Definition: layer.hpp:908
bool get_run_layer_in_subgraph() const noexcept
Definition: layer.hpp:531
void set_run_layer_in_subgraph()
Definition: layer.hpp:528
std::shared_ptr< El::Grid > get_mygrid() const
Definition: layer.hpp:502
EvalType m_fp_compute_time
Time spent in the forward propagation computation.
Definition: layer.hpp:853
size_t num_weights() const noexcept
Definition: layer.hpp:727
Abstract base class for neural network models.
Definition: model.hpp:83
virtual void setup_gpu()
Setup GPU objects. Called by the &#39;setup&#39; function if the layer is on GPUs.
Definition: layer.hpp:782
std::vector< ViewingLayerPtr > m_parent_layers
References to parent layers.
Definition: layer.hpp:1011
bool has_weights() const noexcept
Definition: layer.hpp:728
int get_num_children() const noexcept
Get number of child layers.
Definition: layer.hpp:576
std::weak_ptr< weights > ViewingWeightsPtr
Smart pointer to reference a weights object.
Definition: layer.hpp:89
void reset_inter_subgrid_vc_comm(std::shared_ptr< El::mpi::Comm > mpi_comm)
Definition: layer.hpp:509
ViewingLayerPtr m_hint_layer
Hint layer. During setup, the output tensor dimensions are set to match the first output tensor of th...
Definition: layer.hpp:1033
void set_subgraph_parallelism_execution()
Definition: layer.hpp:515
El::Int get_num_spliting_groups() const
Definition: layer.hpp:499
ParallelStrategy const & get_parallel_strategy() const noexcept
Get the parallel strategy for the layer.
Definition: layer.hpp:400
std::string get_name() const
Get the layer instance&#39;s name.
Definition: layer.hpp:332
void set_num_weights(size_t n)
Definition: layer.hpp:733
std::ostream & print_parallel_strategy_header(std::ostream &os)
Definition: layer.hpp:207
El::BaseDistMatrix BaseDistMat
Definition: base.hpp:121
bool operator!=(const ParallelStrategy &ps) const
Definition: layer.hpp:188
data_layout
Data layout that is optimized for different modes of parallelism.
Definition: base.hpp:218
virtual bool update_compute()
Perform the computation for the update step. Returns false if the layer must reset for a new training...
Definition: layer.hpp:829
ParallelStrategy m_parallel_strategy
Parallel strategy for the layer.
Definition: layer.hpp:1036
virtual void bp_compute()
Compute objective funciton gradients. Called by the &#39;back_prop&#39; function. Given the input...
Definition: layer.hpp:820
void clear_child_layers()
Remove pointers to child layers.
Definition: layer.hpp:601
EvalType m_bp_compute_time
Time spent in the backward propagation computation.
Definition: layer.hpp:857
void set_weights(size_t idx, ViewingWeightsPtr w)
Definition: layer.hpp:734
SubGraphCommunication get_communication_flag()
Definition: layer.hpp:487
bool using_gpus() const noexcept
Whether the layer is using a GPU implementation.
Definition: layer.hpp:417
EvalType m_bp_time
Time spent in backward propagation.
Definition: layer.hpp:855
std::vector< ViewingWeightsPtr > m_weights
References to layer weights.
Definition: layer.hpp:1023
void set_communication_flag(SubGraphCommunication type)
Definition: layer.hpp:481
std::shared_ptr< Layer > OwningLayerPtr
Smart pointer to manage ownership of a layer object.
Definition: layer.hpp:125
bool has_weights(size_t idx) const noexcept
Definition: layer.hpp:729
void set_name(const std::string name)
Set the layer instance&#39;s name. Each layer in a model should have a unique, preferably human-readable...
Definition: layer.hpp:319
bool subgraph_parallelism_execution() const noexcept
Definition: layer.hpp:522
SubGraphCommunication
Definition: layer.hpp:261
std::string m_name
Layer instance&#39;s name. Each layer in a model should have a unique, preferably human-readable, name.
Definition: layer.hpp:865
std::vector< std::vector< int > > m_output_dims_list
Dimensions of output tensors.
Definition: layer.hpp:1026
virtual bool can_run_inplace() const
If True, the computation can run in-place (feeding each input activations tensor as the corresponding...
Definition: layer.hpp:411
double EvalType
Definition: base.hpp:189
std::vector< ViewingLayerPtr > m_child_layers
References to child layers.
Definition: layer.hpp:1013