JuliaDiff / JuliaDiff/ChainRulesCore.jl

Destination flipping for `add!!(x, y)`

Open
#346 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

inplace accumulation
Dominant language
Julia
Stars
267
Forks
66
PR merge metrics
No merged PRs in 30d

Description

Right now add!!(x, y) will only ever mutate x, never y.
because of the logically linear nature of AD, y being a differential (i.e. the output of pullback) means it is used exactly once .
Which means we are infact free to mutate it, also since this will be it's only use. (same also says why we are always ok to mutate x)
See https://github.com/google-research/dex-lang/issues/401#issuecomment-756996758
(and to a lesser extent https://twitter.com/oxinabox_frames/status/1387722380978622468)

So we could pick either x or y depending on which was a valid inplacable_destination.
And maybe also always chose Array if one of them is an Array (since that is the best destination if that has been allocated)

This would solve at least the basic cases of #345

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the add!!(x, y) implementation and the inplacable_destination checks first. Compare how x and y are handled, then validate destination selection against the basic cases referenced by #345, including the Array preference if that behavior is adopted.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend-api-design, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.