Repository navigation
Transformer fix - #167
Transformer fix#167
Conversation
Let's just make dropout a kwarg parameter to the
Let's keep it the way it is implemented in
I think we should have this. And maybe default it to
Seems reasonable to follow PyTorch in that case. Add a comment about it when describing the |
awni
left a comment
There was a problem hiding this comment.
Thanks for the update! I responded to your questions. Please make the corresponding changes and then we can add this!
|
Also do you mind adding a docstring to the |
|
@Jyun1998 are you still planning on updating this? |
Yes! I will finish it within this week with your comments :) |
|
Hi @awni ! Merry Chirstmas :) Added docstring, norm_first, and also activation to replace mx.maximum at ffn layer. There are few points to further discuss.
|
awni
left a comment
There was a problem hiding this comment.
Looks great, just a couple minor comments!
| dropout (float): The dropout value for Transformer encoder/decoder. | ||
| activation (Callable[[Any], Any]): the activation function of encoder/decoder intermediate layer | ||
| custom_encoder (Optional[Any]): A custom encoder to replace the standard Transformer encoder. |
There was a problem hiding this comment.
Add defaults for these as well in the docstring.
Ok with me
I left a comment that might work for shortening this. I don't think you need separate modules for these.
👍 |
|
Also could you rebase? There is a merge conflict |
|
@awni Thanks for the review!
def __call__(self, x, mask):
y = self.ln1(x) if self.norm_first else x
y = self.attention(y, y, y, mask)
y = self.dropout1(y)
x = x + y
x = self.ln1(x) if not self.norm_first else x
y = self.ln2(x) if self.norm_first else x
y = self.linear1(y)
y = self.activation(y)
y = self.dropout2(y)
y = self.linear2(y)
x = x + y
x = self.ln2(x) if not self.norm_first else x
return x |
|
Also rebased :) |
awni
left a comment
There was a problem hiding this comment.
Looks great, thanks for adding!! I pushed a few changes to the doc strings and included stuff in the docs as well!
Thanks for the review :) |
* add transformer with dropout, fix transformer ffm, layernorm order * precommit changes * precommit changes * add docstring, activation, norm_first * run precommit * run precommit * add doctstring * precommit * style nits in docs --------- Co-authored-by: junwoo-yun <junwoo.yun@bagelcode.com> Co-authored-by: Awni Hannun <awni@apple.com>
Proposed changes
Changes
Changed order of layernorm and ffn according to tensorflow and pytorch implementations. (norm_first=False is default in pytroch as well as transformer)
Added Encoder, Decoder with Dropout
Parts want to discuss
Do you want to use Transformer with Dropout as main class?
Do you like to add ffn as function or classes?
Do you like to add norm_first parameter so that you could choose to do layer_norm first or later?
Tensorflow do not do dropout with ffn while pytorch do. Which one should I refer to?
I guess you did not add dropout since you would like to benchmark transformer without dropout for all jax, torch, tensorflow, mlx. I also had trouble adding dropout for jax.
Testing
Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes