MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / init

Method init

src/opr/impl/loop/grad.cpp:393–410  ·  view source on GitHub ↗

! * \brief initialize for given output vars * \param dest_vars vars in fwd graph needed to give grad */

Source from the content-addressed store, hash-verified

391 * \param dest_vars vars in fwd graph needed to give grad
392 */
393 void init(const VarNodeArray& dest_vars) {
394 mgb_assert(m_var_fwd2grad.empty() && !dest_vars.empty());
395 SubgraphDepIter iter;
396 for (auto i : dest_vars)
397 iter.add(i);
398
399 for (auto i : iter.oprs()) {
400 process_opr(i);
401 }
402
403 for (auto i : iter.input_makers()) {
404 process_input_maker(i);
405 }
406
407 for (auto&& i : m_var_fwd2grad) {
408 mgb_assert(i.second->owner_graph() == m_grad_desc->sub_graph());
409 }
410 }
411
412 //! get var in grad graph corresponding to given var in fwd graph
413 VarNode* map_var(VarNode* fwd_var) const { return m_var_fwd2grad.at(fwd_var); }

Callers 1

init_virtual_lossMethod · 0.45

Calls 4

sub_graphMethod · 0.80
emptyMethod · 0.45
addMethod · 0.45
owner_graphMethod · 0.45

Tested by

no test coverage detected