-
Notifications
You must be signed in to change notification settings - Fork 24
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
🦙 Llama3 on TGI - Jetstream Pytorch #90
Merged
Merged
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
26fdbf8
fix(engine_loader): correct n_reps and cache_shape settings
tengomucho 1d63b07
feat(tokenizer): donwload all json files when fetching model
tengomucho d858713
feat(jetstream pt): relax llama compatibility requirements
tengomucho 8ce7762
test(jetstream pt): move Llama2-7b test to runslow/nightly
tengomucho 71ba46e
fix(jetstream pt): clone weight before mapping
tengomucho b323794
test(jetstream pt): add test showing support of Llama3-8B
tengomucho 6857b5f
review: fix imports for type checking
tengomucho c9f11da
fix: correct type hint
tengomucho 525231a
fix(pyproject): correct jetstream git revision
tengomucho 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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,19 +11,17 @@ | |||||
QuantizationConfig, | ||||||
) | ||||||
from loguru import logger | ||||||
from transformers import AutoConfig | ||||||
from transformers import AutoConfig, PretrainedConfig | ||||||
|
||||||
from .engine import HfEngine | ||||||
from .llama_model_exportable_hf import TransformerHf | ||||||
|
||||||
|
||||||
def load_llama_model_info(model_path: str) -> Any: | ||||||
# First get config | ||||||
config = AutoConfig.from_pretrained(model_path) | ||||||
def load_llama_model_info(config: PretrainedConfig) -> Any: | ||||||
num_layers = config.num_hidden_layers | ||||||
num_heads = config.num_attention_heads | ||||||
head_dim = config.hidden_size // num_heads | ||||||
n_reps = config.num_key_value_heads // num_heads | ||||||
n_reps = num_heads // config.num_key_value_heads | ||||||
model_info = fetch_models.ModelInfo( | ||||||
TransformerHf, | ||||||
num_layers=num_layers, | ||||||
|
@@ -34,10 +32,10 @@ def load_llama_model_info(model_path: str) -> Any: | |||||
return model_info | ||||||
|
||||||
|
||||||
def load_model_info(model_path: str) -> Any: | ||||||
config = AutoConfig.from_pretrained(model_path) # For now only Llama 2 is supported | ||||||
def load_model_info(config: PretrainedConfig) -> Any: | ||||||
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.
Suggested change
|
||||||
# For now only Llama is supported | ||||||
if config.model_type == "llama": | ||||||
return load_llama_model_info(model_path) | ||||||
return load_llama_model_info(config) | ||||||
# Other models supports can be added here later | ||||||
return None | ||||||
|
||||||
|
@@ -49,7 +47,9 @@ def create_engine_env_data( | |||||
max_input_tokens: int, | ||||||
max_output_tokens: int, | ||||||
) -> Any: | ||||||
model_info = load_model_info(model_path) | ||||||
# First get config | ||||||
config = AutoConfig.from_pretrained(model_path) | ||||||
model_info = load_model_info(config) | ||||||
if model_info is None: | ||||||
return None | ||||||
|
||||||
|
@@ -72,7 +72,7 @@ def create_engine_env_data( | |||||
) | ||||||
env_data.cache_shape = ( | ||||||
batch_size, | ||||||
model_info.num_heads, | ||||||
config.num_key_value_heads, | ||||||
max_cache_length, | ||||||
model_info.head_dim, | ||||||
) | ||||||
|
@@ -91,7 +91,8 @@ def instantiate_model_from_repo_id( | |||||
env: Any, | ||||||
): | ||||||
"""Create model instance by hf model_dir, and its config""" | ||||||
model_info = load_model_info(model_dir) | ||||||
config = AutoConfig.from_pretrained(model_dir) | ||||||
model_info = load_model_info(config) | ||||||
# at this point we can be quite optimistic and just assert | ||||||
assert model_info is not None | ||||||
|
||||||
|
@@ -117,7 +118,8 @@ def shard_weights(env, weights, weight_shardings): | |||||
for key, val in weights.items(): | ||||||
sharding = env.sharding_by_axis(weight_shardings.get(key, -1)) | ||||||
with jax.default_device(jax.devices("cpu")[0]): | ||||||
arr = torch_xla2.tensor.t2j(val) | ||||||
# Note we clone to avoid a core-dump that might happen otherwise when calling device_put | ||||||
arr = torch_xla2.tensor.t2j(val.clone()) | ||||||
arr = jax.device_put(arr, sharding) | ||||||
sharded[key] = torchjax.to_torch(arr) | ||||||
return sharded | ||||||
|
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
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.