forked from axolotl-ai-cloud/axolotl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Sample packing for phi arch (axolotl-ai-cloud#586)
* phi sequence packing * sample packing fixes * fix linting * fix inference and phi e2e tests * update phi example now that sample packing works * wandb import keeps getting moved around
- Loading branch information
Showing
10 changed files
with
1,138 additions
and
23 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
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
Empty file.
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,6 @@ | ||
""" | ||
MixFormers model architecture used for phi models | ||
""" | ||
|
||
from .configuration_mixformer_sequential import MixFormerSequentialConfig # noqa | ||
from .modeling_mixformer_sequential import MixFormerSequentialForCausalLM # noqa |
63 changes: 63 additions & 0 deletions
63
src/axolotl/models/phi/configuration_mixformer_sequential.py
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,63 @@ | ||
# pylint: skip-file | ||
|
||
# Copyright (c) Microsoft Corporation. | ||
# Licensed under the MIT license. | ||
|
||
import math | ||
from typing import Any, Dict, List, Optional, Union | ||
|
||
from transformers import PretrainedConfig | ||
|
||
|
||
class MixFormerSequentialConfig(PretrainedConfig): | ||
"""MixFormer (sequential for DeepSpeed) configuration.""" | ||
|
||
model_type = "mixformer-sequential" | ||
|
||
attribute_map = { | ||
"max_position_embeddings": "n_positions", | ||
"hidden_size": "n_embd", | ||
"num_attention_heads": "n_head", | ||
"num_hidden_layers": "n_layer", | ||
"input_emb_layer": "embd_layer", # `input_emb_layer` key is for backward compatibility | ||
"blocks": "architecture", # `blocks` key is for backward compatibility | ||
} | ||
|
||
def __init__( | ||
self, | ||
vocab_size: Optional[int] = 50304, | ||
n_positions: Optional[int] = 2048, | ||
n_embd: Optional[int] = 1024, | ||
n_layer: Optional[int] = 20, | ||
n_inner: Optional[int] = None, | ||
n_head: Optional[int] = 16, | ||
rotary_dim: Optional[int] = 32, | ||
activation_function: Optional[str] = "gelu_new", | ||
embd_layer: Optional[str] = "default", | ||
architecture: Union[Dict[str, Any], List[Dict[str, Any]]] = None, | ||
embd_pdrop: Optional[float] = 0.0, | ||
resid_pdrop: Optional[float] = 0.0, | ||
layer_norm_epsilon: Optional[float] = 1e-5, | ||
initializer_range: Optional[float] = 0.02, | ||
tie_word_embeddings: Optional[bool] = False, | ||
pad_vocab_size_multiple: Optional[int] = 64, | ||
**kwargs | ||
) -> None: | ||
self.vocab_size = int( | ||
math.ceil(vocab_size / pad_vocab_size_multiple) * pad_vocab_size_multiple | ||
) | ||
self.n_positions = n_positions | ||
self.n_embd = n_embd | ||
self.n_layer = n_layer | ||
self.n_inner = n_inner | ||
self.n_head = n_head | ||
self.rotary_dim = min(rotary_dim, n_embd // n_head) | ||
self.activation_function = activation_function | ||
self.embd_layer = embd_layer | ||
self.architecture = architecture | ||
self.embd_pdrop = embd_pdrop | ||
self.resid_pdrop = resid_pdrop | ||
self.layer_norm_epsilon = layer_norm_epsilon | ||
self.initializer_range = initializer_range | ||
|
||
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs) |
Oops, something went wrong.