Skip to content

jnp.dot vs explicit dot product followed by jnp.sum results in drastically different memory uses #17924

Answered by jakevdp
FilipeMaia asked this question in Q&A
Discussion options

You must be logged in to vote

Hi - thanks for the question! I think in some sense this is expected, in that different ways of expressing computations will in general lead to different usage of computational and memory resources. In a perfect world the XLA compiler would be able to recognize that these two sequences of operations are equivalent and choose the best approach given the resources available, but no perfect compiler exists.

I'll address one of your points directly:

It seems in the second case the full result out of vmap is generated before the sum, instead of doing the sum as the vmap proceeds.

As far as I know, the XLA computational model will never "do the sum as the vmap proceeds". XLA is designed with …

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@FilipeMaia
Comment options

@jakevdp
Comment options

@FilipeMaia
Comment options

Answer selected by FilipeMaia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants