-
Notifications
You must be signed in to change notification settings - Fork 16
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
Mixtral enablement. #120
Merged
Mixtral enablement. #120
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c5c0772
Initial Mixtral enablement.
wang2yn84 277b02c
Adds the mistral tokenizer model.
wang2yn84 8be8c36
Updates the convert checkpoint file to handle mistral model.
wang2yn84 ab8c802
Renames the typo of the model name.
wang2yn84 98fdf71
Fixing checkpoing loading. Still has some issue. Push to debug.
wang2yn84 aa78dbd
Running on CPU working, temporarily disable the generate jit to see i…
wang2yn84 1846cf9
Fix checkpoint loading issue. Right now loading from the gpt-fast con…
wang2yn84 8be6cfc
Fix the ckpt conversion script for mistral model. Fix the freqs_cis f…
wang2yn84 e6c5696
Add quantized layer for moe
qihqi 518f758
Add the huggingface download script. Improved the convert checkpoints…
wang2yn84 147cef4
Clean up and fix lint errors.
wang2yn84 2ed3e0e
Missing cleanups.
wang2yn84 14d6672
Add instructions for Mixtral.
wang2yn84 b2a6a18
Renames everything from mistral to mixtral.
wang2yn84 c004adc
Fix more lint errors.
wang2yn84 a206374
Removes the unnecessary checkpoint name mapping from the original Mix…
wang2yn84 d18f8c3
Fix the model calling arg sequence; Fix the checkpoint convert script.
wang2yn84 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
# Sharding config for mixtral | ||
# Sharding should either be an int between 0 and rank - 1 | ||
# signifying the axis to shard or -1 / null signifying replicated | ||
|
||
|
||
freqs_cis : -1 # torch.complex64 (2048, 64) | ||
tok_embeddings.weight : 1 # torch.float32 (vocab_size, 4096) | ||
tok_embeddings.weight_scaler : 0 # torch.bfloat16 (4096,) | ||
layers.*.attention.wo.weight : 1 # torch.int8 (4096, 4096) | ||
layers.*.attention.wo.weight_scaler : -1 # torch.bfloat16 (4096,) | ||
layers.*.attention.wq.weight : 0 # torch.int8 (4096, 4096) | ||
layers.*.attention.wq.weight_scaler : 0 # torch.bfloat16 (4096,) | ||
layers.*.attention.wk.weight : 0 # torch.int8 (4096, 4096) | ||
layers.*.attention.wk.weight_scaler : 0 # torch.bfloat16 (4096,) | ||
layers.*.attention.wv.weight : 0 # torch.int8 (4096, 4096) | ||
layers.*.attention.wv.weight_scaler : 0 # torch.bfloat16 (4096,) | ||
layers.*.attention.wqkv.weight : 0 # torch.int8 (4096, 4096) | ||
layers.*.attention.wqkv.weight_scaler : 0 # torch.bfloat16 (4096,) | ||
layers.*.block_sparse_moe.gate.weight: -1 | ||
layers.*.block_sparse_moe.gate.weight_scaler: -1 | ||
layers.*.block_sparse_moe.cond_ffn.w1: 1 | ||
layers.*.block_sparse_moe.cond_ffn.w1_scaler: 1 | ||
layers.*.block_sparse_moe.cond_ffn.w2: 2 | ||
layers.*.block_sparse_moe.cond_ffn.w2_scaler: -1 | ||
layers.*.block_sparse_moe.cond_ffn.w3: 1 | ||
layers.*.block_sparse_moe.cond_ffn.w3_scaler: 1 | ||
layers.*.ffn_norm.weight : -1 # torch.float32 (4096,) | ||
layers.*.attention_norm.weight : -1 # torch.float32 (4096,) | ||
norm.weight : -1 # torch.float32 (4096,) | ||
output.weight : 0 # torch.float32 (vocab_size, 4096) | ||
output.weight_scaler : 0 # torch.float32 (4096,) |
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
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,78 @@ | ||
# pylint: disable-all | ||
# # Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# Mixtral model config | ||
import dataclasses | ||
from dataclasses import dataclass | ||
|
||
|
||
def find_multiple(n: int, k: int) -> int: | ||
if n % k == 0: | ||
return n | ||
return n + k - (n % k) | ||
|
||
|
||
@dataclass | ||
class ModelArgs: | ||
block_size: int = 2048 | ||
vocab_size: int = 32000 | ||
n_layer: int = 32 | ||
n_head: int = 32 | ||
dim: int = 4096 | ||
intermediate_size: int = None | ||
n_local_heads: int = -1 | ||
head_dim: int = 64 | ||
rope_base: float = 10000 | ||
norm_eps: float = 1e-5 | ||
num_experts: int = 8 | ||
num_activated_experts: int = 2 | ||
device: str = "meta" | ||
|
||
def __post_init__(self): | ||
if self.n_local_heads == -1: | ||
self.n_local_heads = self.n_head | ||
if self.intermediate_size is None: | ||
hidden_dim = 4 * self.dim | ||
n_hidden = int(2 * hidden_dim / 3) | ||
self.intermediate_size = find_multiple(n_hidden, 256) | ||
self.head_dim = self.dim // self.n_head | ||
|
||
@classmethod | ||
def from_name(cls, name: str): | ||
if name in transformer_configs: | ||
return cls(**transformer_configs[name]) | ||
# fuzzy search | ||
config = [ | ||
config | ||
for config in transformer_configs | ||
if config in str(name).upper() or config in str(name) | ||
] | ||
assert len(config) == 1, name | ||
return cls(**transformer_configs[config[0]]) | ||
|
||
|
||
transformer_configs = { | ||
"Mixtral-8x7B-v0.1": dict( | ||
block_size=32768, | ||
n_layer=32, | ||
n_head=32, | ||
n_local_heads=8, | ||
dim=4096, | ||
intermediate_size=14336, | ||
rope_base=1000000.0, | ||
num_experts=8, | ||
num_activated_experts=2, | ||
), | ||
} |
Oops, something went wrong.
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.
Looks like only these weight name are difference, can we only store the the different name in the map?
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.
Good point, removed