-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from foundation-model-stack/meta_init
switch to new meta device init method
- Loading branch information
Showing
4 changed files
with
36 additions
and
19 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from .ac_handler import apply_fsdp_checkpointing | ||
from .mixed_precision import * | ||
from .param_init import param_init_function | ||
from .wrapping import get_llama_wrapper |
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 @@ | ||
import torch | ||
from fms.modules.attention import MultiHeadAttention | ||
from fms.modules.embedding import WordEmbedding | ||
from fms.modules.feedforward import GatedLinearUnit | ||
from fms.modules.layernorm import LayerNormParameterized | ||
|
||
|
||
# for details, read https://github.com/foundation-model-stack/fms-fsdp/issues/64 | ||
def param_init_function(module): | ||
if ( | ||
isinstance(module, MultiHeadAttention) | ||
or isinstance(module, WordEmbedding) | ||
or isinstance(module, GatedLinearUnit) | ||
or isinstance(module, LayerNormParameterized) | ||
): | ||
module.to_empty(device=torch.cuda.current_device()) | ||
with torch.no_grad(): | ||
module.reset_parameters() |
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