You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm new to JAX but I wasn't able to find an answer to this anywhere. I am building a BERT-like language model with MLM loss on about 15% of all input tokens.
Given hidden outputs h of shape [sequence, features], the output emedding W of shape [features, vocab], target y of shape [sequence], and dynamic boolean mask mask of shape [sequence] where about 15% of all values are True, I only need loss values for masked tokens, i. e.: cross_entropy(softmax(h @ W), one_hot(y))[mask].mean().
Without JIT, I would save memory by doing h[mask] @ W instead, but with JIT, arrays of dynamic size are not allowed.
It seems important though, because the matrix [sequence, vocab] if of course quite large. Is there a way for me to make sure the optimizer does not produce unnecessary rows without creating arrays of dynamic shapes, given that mask is dynamic and has slightly different number of True values at each step? Or is the only way to change my strategy and mask exactly 15% of each sample instead, so that the shapes are static?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm new to JAX but I wasn't able to find an answer to this anywhere. I am building a BERT-like language model with MLM loss on about 15% of all input tokens.
Given hidden outputs
h
of shape[sequence, features]
, the output emeddingW
of shape[features, vocab]
, targety
of shape[sequence]
, and dynamic boolean maskmask
of shape[sequence]
where about 15% of all values areTrue
, I only need loss values for masked tokens, i. e.:cross_entropy(softmax(h @ W), one_hot(y))[mask].mean()
.Without JIT, I would save memory by doing
h[mask] @ W
instead, but with JIT, arrays of dynamic size are not allowed.It seems important though, because the matrix
[sequence, vocab]
if of course quite large. Is there a way for me to make sure the optimizer does not produce unnecessary rows without creating arrays of dynamic shapes, given thatmask
is dynamic and has slightly different number ofTrue
values at each step? Or is the only way to change my strategy and mask exactly 15% of each sample instead, so that the shapes are static?Beta Was this translation helpful? Give feedback.
All reactions