Skip to content
fn

rebase_views

void rebase_views(const int & a)

Re-derive the other members of a's view family after a write through a.

Every member reads one run of the buffer, as a does, so the write changed exactly the part of each member the two runs share. Autograd has to say so, or the member sends its gradient to the values the write replaced:

  • a member the write missed keeps its values, and so its graph;
  • a member the write covered reads only a's values now — a reshape of a when the runs are the same, a run of a otherwise — and when a does not require grad it is cut from the graph, since those are a constant's values;
  • a member the write reached into has a's part spliced into its old graph by a CopySlices node, as the reference does for the base of a written slice. When a does not require grad, that part just stops passing gradient back.

A leaf that requires grad keeps its place and only its values move: the write was into its base or beside it, since write_through refuses one through a view of it while autograd records.