-
Notifications
You must be signed in to change notification settings - Fork 27.6k
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
Add Zamba2 #34517
Draft
pglorio
wants to merge
76
commits into
huggingface:main
Choose a base branch
from
Zyphra:zamba2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Add Zamba2 #34517
Changes from 23 commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
acd25b7
First commit
pglorio 70639b8
Finish model implementation
pglorio d111b98
First commit
pglorio 8f36dba
Finish model implementation
pglorio f0c547c
Merge branch 'zamba2' of https://github.com/Zyphra/transformers_zamba…
pglorio 700fbf0
Register zamba2
pglorio 70a6021
generated modeling and configuration
pglorio 88c4b26
Merge pull request #2 from Zyphra/main
pglorio 685906a
generated modeling and configuration
pglorio 4da8d5f
added hybrid cache
pglorio 6b5a9be
fix attention_mask in mamba
pglorio 248350d
dropped unused loras
pglorio d1d2c66
fix flash2
pglorio eb6063e
Merge pull request #3 from Zyphra/main
pglorio 5f5d01e
config docstrings
c1b7647
fix config and fwd pass
pglorio 979b99b
make fixup fixes
pglorio 9d9b2eb
text_modeling_zamba2
pglorio 3a457f5
Merge pull request #4 from Zyphra/main
pglorio 549d4cb
small fixes
pglorio 987bba9
make fixup fixes
pglorio ffc2a58
Merge pull request #5 from Zyphra/main
pglorio 9adf85e
Fix modular model converter
pglorio 904da4e
added inheritances in modular, renamed zamba cache
pglorio 4725983
Merge pull request #6 from Zyphra/main
pglorio 0be27d7
modular rebase
pglorio cc0c549
Rebase
pglorio ac77a09
new modular conversion
pglorio e59980e
fix generated modeling file
pglorio 73a647a
fixed import for Zamba2RMSNormGated
pglorio c2b72a5
modular file cleanup
pglorio 0eb39a5
rebase
pglorio 10a0b1e
make fixup and model tests
pglorio 0270667
dropped inheritance for Zamba2PreTrainedModel
pglorio 189c8c5
make fixup and unit tests
pglorio fa5f79e
Add inheritance of rope from GemmaRotaryEmbedding
pglorio 8079ae0
moved rope to model init
pglorio d6206eb
drop del self.self_attn and del self.feed_forward
pglorio f832699
Rebase onto upstream
pglorio cf613b7
fix tests
pglorio 337faed
renamed lora -> adapter
pglorio f1b31a1
rewrote adapter implementation
pglorio 8925c15
rebase
pglorio 11fdd47
fixed tests
pglorio 02dd042
Merge branch 'main' into zamba2
pglorio 5d0a5d4
Fix torch_forward in mamba2 layer
pglorio ef055c9
Fix torch_forward in mamba2 layer
pglorio b993a78
Fix torch_forward in mamba2 layer
pglorio bf93251
Dropped adapter in-place sum
pglorio 99708af
removed rope from attention init
pglorio d9b4a50
updated rope
pglorio 095d853
created get_layers method
pglorio 10ebad5
rebase
pglorio 99e343e
make fixup fix
pglorio 4e40975
make fixup fixes
pglorio 61bb32f
make fixup fixes
pglorio bb9b24b
fix merge conflicts
pglorio cb90bb4
update to new attention standard
pglorio 8ed701e
fixes for merge
pglorio 1dbc8c7
update to new attention standard
pglorio f24e452
make fixup fixes
pglorio 676f862
rebase
pglorio 2b29338
minor fixes
pglorio b212cb2
cache_position
pglorio 1e3b51e
removed cache_position postion_ids use_cache
pglorio 5ace701
remove config from modular
pglorio 535b631
removed config from modular (2)
pglorio 5a16aa9
rebase
pglorio 1c92266
import apply_rotary_pos_emb from llama
pglorio 99bde93
fixed rope_kwargs
pglorio baf2ed3
Instantiate cache in Zamba2Model
pglorio 9afb57e
fix cache
pglorio d1687f9
fix @slow decorator
pglorio 4299889
rebase
pglorio a0545bf
rebase
pglorio 903f6dc
small fix in modular file
pglorio 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<!--Copyright 2024 The HuggingFace Team. All rights reserved. | ||
|
||
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. | ||
|
||
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be | ||
rendered properly in your Markdown viewer. | ||
|
||
--> | ||
# Zamba2 | ||
|
||
Zamba2 is a large language model (LLM) trained by Zyphra, and made available under an Apache 2.0 license. Please see the [Zyphra Hugging Face](https://huggingface.co/collections/zyphra/) repository for model weights. | ||
|
||
This model was contributed by [pglo](https://huggingface.co/pglo). | ||
|
||
|
||
## Model details | ||
|
||
Zamba2-1.2B, Zamba2-2.7B and Zamba2-7B are hybrid models combining state-space models (Specifically [Mamba](https://github.com/state-spaces/mamba)) and transformer, and were trained using next-token prediction. Zamba2 uses shared transformer layers after every 6 mamba blocks. It uses the [Mistral v0.1 tokenizer](https://huggingface.co/mistralai/Mistral-7B-v0.1). We came to this architecture after a series of ablations at small scales. Zamba2-1.2B, Zamba2-2.7B and Zamba2-7B were pre-trained on 2T and 3T tokens, respectively. | ||
|
||
<img src=https://github.com/user-attachments/assets/c2cff209-b901-483c-87aa-774b82a0769f width=30% height=40% /> | ||
|
||
## Quick start | ||
|
||
|
||
### Presequities | ||
|
||
Zamba2 requires you use `transformers` version 4.46.0 or higher: | ||
```bash | ||
pip install transformers>=4.46.0 | ||
``` | ||
|
||
## Inference | ||
|
||
```python | ||
from transformers import AutoTokenizer, AutoModelForCausalLM | ||
import torch | ||
|
||
tokenizer = AutoTokenizer.from_pretrained("Zyphra/Zamba2-7B") | ||
model = AutoModelForCausalLM.from_pretrained("Zyphra/Zamba2-7B", device_map="cuda", torch_dtype=torch.bfloat16) | ||
|
||
input_text = "What factors contributed to the fall of the Roman Empire?" | ||
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda") | ||
|
||
outputs = model.generate(**input_ids, max_new_tokens=100) | ||
print(tokenizer.decode(outputs[0])) | ||
``` | ||
|
||
|
||
## Model card | ||
|
||
The model cards can be found at: | ||
* [Zamba2-1.2B](https://huggingface.co/Zyphra/Zamba2-1.2B) | ||
* [Zamba2-2.7B](https://huggingface.co/Zyphra/Zamba2-2.7B) | ||
* [Zamba2-7B](https://huggingface.co/Zyphra/Zamba2-7B) | ||
|
||
|
||
## Issues | ||
For issues with model output, or community discussion, please use the Hugging Face community [forum](https://huggingface.co/Zyphra/Zamba2-7B/discussions) | ||
|
||
|
||
## License | ||
|
||
The model weights are open-sourced via an Apache 2.0 license. | ||
|
||
|
||
## Zamba2Config | ||
|
||
[[autodoc]] Zamba2Config | ||
|
||
|
||
## Zamba2Model | ||
|
||
[[autodoc]] Zamba2Model | ||
- forward | ||
|
||
|
||
## Zamba2ForCausalLM | ||
|
||
[[autodoc]] Zamba2ForCausalLM | ||
- forward | ||
|
||
|
||
## Zamba2ForSequenceClassification | ||
|
||
[[autodoc]] transformers.Zamba2ForSequenceClassification | ||
- forward |
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 |
---|---|---|
|
@@ -285,5 +285,6 @@ | |
yolos, | ||
yoso, | ||
zamba, | ||
zamba2, | ||
zoedepth, | ||
) |
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,57 @@ | ||
# Copyright 2024 The HuggingFace Team. All rights reserved. | ||
# | ||
# 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. | ||
from typing import TYPE_CHECKING | ||
|
||
from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available | ||
|
||
|
||
_import_structure = { | ||
"configuration_zamba2": ["Zamba2Config"], | ||
} | ||
|
||
|
||
try: | ||
if not is_torch_available(): | ||
raise OptionalDependencyNotAvailable() | ||
except OptionalDependencyNotAvailable: | ||
pass | ||
else: | ||
_import_structure["modeling_zamba2"] = [ | ||
"Zamba2ForCausalLM", | ||
"Zamba2ForSequenceClassification", | ||
"Zamba2Model", | ||
"Zamba2PreTrainedModel", | ||
] | ||
|
||
if TYPE_CHECKING: | ||
from .configuration_zamba2 import Zamba2Config | ||
|
||
try: | ||
if not is_torch_available(): | ||
raise OptionalDependencyNotAvailable() | ||
except OptionalDependencyNotAvailable: | ||
pass | ||
else: | ||
from .modeling_zamba2 import ( | ||
Zamba2ForCausalLM, | ||
Zamba2ForSequenceClassification, | ||
Zamba2Model, | ||
Zamba2PreTrainedModel, | ||
) | ||
|
||
|
||
else: | ||
import sys | ||
|
||
sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__) | ||
pglorio marked this conversation as resolved.
Show resolved
Hide resolved
|
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.