-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2/n - Make Gemma use regular TransformerDecoder #1553
Merged
felipemello1
merged 18 commits into
pytorch:main
from
felipemello1:gemma_deprecate_tied_transformer
Sep 12, 2024
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4690b9b
use identity for dropout if 0
17e6d79
update model builders
b0154b9
add lora dropout to configs
e27f736
typo
051f472
Merge branch 'main' into set_dropout_zero
002d67f
add missing lora dropout
d430c1f
Merge branch 'main' into remove_tied_embeddings
6adf19f
update qwen
c6dd298
change typehint
a55f9ae
import deprecated
b427bf5
update import
f54904e
add tied linear
a0bd26b
remove unused import
2500a4c
update gemma
ceeba8f
Merge branch 'remove_tied_embeddings' into gemma_deprecate_tied_trans…
1bdcf01
typehint
4e1e8a6
Merge branch 'main' of github.com:pytorch/torchtune into gemma_deprec…
175782f
update docstring
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
|
||
class GemmaNormEmbeddings(nn.Embedding): | ||
def __init__(self, in_dim: int, out_dim: int): | ||
super().__init__(in_dim, out_dim) | ||
self.out_dim = out_dim | ||
|
||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
x = super().forward(x) | ||
return x * torch.tensor(self.out_dim**0.5, dtype=x.dtype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,32 +5,27 @@ | |
# LICENSE file in the root directory of this source tree. | ||
|
||
import os | ||
from typing import Union | ||
|
||
import torch | ||
from torch import nn | ||
|
||
from torchtune.modules import ( | ||
TiedEmbeddingTransformerDecoder, | ||
TransformerDecoder, | ||
TransformerSelfAttentionLayer, | ||
) | ||
from torchtune.modules import TransformerDecoder, TransformerSelfAttentionLayer | ||
from torchtune.modules.loss import CEWithChunkedOutputLoss | ||
from torchtune.utils import get_logger, torch_version_ge | ||
|
||
log = get_logger("INFO") | ||
|
||
|
||
def compile_model( | ||
model: Union[TransformerDecoder, TiedEmbeddingTransformerDecoder], | ||
model: TransformerDecoder, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why wasn't this handled in 1/n? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I forgot and left a comment that i was doing it in 2/n |
||
verbose: bool = True, | ||
) -> None: | ||
""" | ||
Utility to compile a transformer model inplace. On PyTorch nightlies we use per-layer compile | ||
to reduce compile times. Otherwise we compile the full model, which takes longer. | ||
|
||
Args: | ||
model (Union[TransformerDecoder, TiedEmbeddingTransformerDecoder]): A transformer model to compile. | ||
model (TransformerDecoder): A transformer model to compile. | ||
verbose (bool): Whether to log compile info. Default: True | ||
Returns: | ||
None | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstrings, esp to explain why this is a separate class