MCPcopy Create free account
hub / github.com/LBANN/lbann / backward_prop

Method backward_prop

src/models/model.cpp:1584–1664  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1582}
1583
1584void model::backward_prop(bool compute_weight_grads_only)
1585{
1586 LBANN_CALIPER_MARK_FUNCTION;
1587
1588 // Layers disabled due to not propagating error signals through
1589 std::unordered_set<const Layer*> disabled_layers;
1590 auto const& arg_parser = global_argument_parser();
1591 bool const envvar_disable_layers =
1592 !arg_parser.get<bool>(LBANN_OPTION_NO_BACKPROP_DISABLE);
1593
1594 do_model_backward_prop_begin_cbs();
1595
1596 for (El::Int i = get_num_layers() - 1; i >= 0; --i) {
1597
1598 // Perform backward prop step on current layer
1599 auto& l = get_layer(i);
1600 bool enable_layer = (!envvar_disable_layers ||
1601 disabled_layers.find(&l) == disabled_layers.end());
1602
1603 // Check if all children skip gradient backpropagation
1604 if (enable_layer && envvar_disable_layers) {
1605 bool all_children_skip_gradient = l.get_num_children() > 0;
1606 for (auto& child : l.get_child_layers()) {
1607 if (disabled_layers.find(child) != disabled_layers.end())
1608 continue;
1609 all_children_skip_gradient &=
1610 (child->get_backprop_requirements() == PROPAGATE_NOTHING);
1611 if (!all_children_skip_gradient)
1612 break;
1613 }
1614
1615 // Start disabling layers from this point onwards
1616 if (all_children_skip_gradient) {
1617 enable_layer = false;
1618 disabled_layers.insert(&l);
1619 }
1620 }
1621
1622 if (this->is_subgraph_parallelism_enabled()) {
1623 if (l.get_run_layer_in_subgraph()) {
1624 do_layer_backward_prop_begin_cbs(&l);
1625 if (enable_layer)
1626 l.back_prop();
1627 do_layer_backward_prop_end_cbs(&l);
1628 }
1629 else {
1630 // To Do: Fix last batch problem in sub-graph parallelism
1631 // experimental code to fix last batch problem in subgraph parallelism
1632 }
1633 }
1634 else {
1635 do_layer_backward_prop_begin_cbs(&l);
1636 if (enable_layer)
1637 l.back_prop();
1638 do_layer_backward_prop_end_cbs(&l);
1639 }
1640
1641 // Terminate early if all gradients have been computed

Callers 3

kfac.cppFile · 0.45
model_test.cppFile · 0.45

Calls 10

endMethod · 0.80
get_num_childrenMethod · 0.80
get_child_layersMethod · 0.80
insertMethod · 0.80
back_propMethod · 0.80
get_optimizerMethod · 0.80

Tested by

no test coverage detected