-
Notifications
You must be signed in to change notification settings - Fork 31.3k
Add Apertus #39381
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
Merged
Merged
Add Apertus #39381
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
77810b8
init swissai model
haeggee bcdaf70
AutoModelForCausalLM
haeggee 53a3755
AutoModelForCausalLM mapping
haeggee 7c648e7
qk norm and post ln optional
haeggee d9a923d
fix wrong shape of qk norm: megatron uses head_dim
haeggee f35ee01
automodel fixes
haeggee e6921f7
minor fix in forward
haeggee 46ca1ae
fix rope validation to accept llama3 scaling
dhia680 994b1d7
`SwissAIForTokenClassification` support
EduardDurech 8b38b5a
Align `SwissAI` to v4.52.4
EduardDurech 0ffc9b9
Align `SwissAI` to v4.53.1
EduardDurech 7793c87
Init CUDA xIELU
EduardDurech 590957b
`SwissAI*`->`Apertus*`
EduardDurech 353c6c0
ci fix
EduardDurech 833f5fe
check_docstring ignore ApertusConfig
EduardDurech f0ec65c
Licensing and placeholder tests
EduardDurech 1f4e715
Placeholder doc
EduardDurech cf12582
XIELU syntax
EduardDurech 331fc0d
`_xielu_python` optimization
EduardDurech 2728d3c
Fix xIELU
EduardDurech d0d42cd
[tmp] `{beta,eps}` persistent=False
EduardDurech 543b343
Modular `Apertus`
EduardDurech 4d436d0
CUDA xIELU logging
EduardDurech 35d6bb3
Merge upstream/main into model/apertus
EduardDurech e5ec231
ci fix
EduardDurech 1de44fd
ci fix
EduardDurech 9c0cb61
ci fix
EduardDurech 8f1c081
Update license
EduardDurech dad00ca
Update tests/models/apertus/test_modeling_apertus.py
EduardDurech cd029ab
`.utils.import_utils.is_torchdynamo_compiling`
EduardDurech 250b43a
`Apertus` class ordering
EduardDurech c4b6d76
`past_key_value{->s}`, `make fix-copies`
EduardDurech 9865539
ci fix
EduardDurech a7abf5e
Remove unused configuration parameters
EduardDurech 273da51
`{beta,eps}` saved in checkpoint
EduardDurech 29da453
`{beta,eps}` Temporarily on CPU
EduardDurech 792b7de
Suggestions
EduardDurech c2b3de5
Merge branch 'main' into model/apertus
EduardDurech a5889da
ci fix
EduardDurech e19d543
remove fx_compatible (deprecated)
dhia680 69c46ed
remove `rotary_embedding_layer`
dhia680 864c4dd
fully removing `Mask4DTestHard` class
dhia680 e7d03ad
switch to `dtype` instead of `torch_dtype`
dhia680 c394446
remove unused imports
dhia680 68c6def
remove `cache_implementation="static"`
dhia680 227f026
+Apertus to `docs/source/en/_toctree.yml` for the doc builder
dhia680 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 hidden or 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 hidden or 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,100 @@ | ||
| <!--Copyright 2025 The HuggingFace Team and the Swiss AI Initiative. 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. | ||
|
|
||
| --> | ||
|
|
||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="PyTorch" src="https://img.shields.io/badge/PyTorch-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| <img alt="Tensor parallelism" src="https://img.shields.io/badge/Tensor%20parallelism-06b6d4?style=flat&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # Apertus | ||
|
|
||
| [Apertus](https://www.swiss-ai.org) is a family of large language models from the Swiss AI Initiative. | ||
|
|
||
| > [!TIP] | ||
| > Coming soon | ||
|
|
||
| The example below demonstrates how to generate text with [`Pipeline`] or the [`AutoModel`], and from the command line. | ||
|
|
||
| <hfoptions id="usage"> | ||
| <hfoption id="Pipeline"> | ||
|
|
||
| ```py | ||
| import torch | ||
| from transformers import pipeline | ||
|
|
||
| pipeline = pipeline( | ||
| task="text-generation", | ||
| model="swiss-ai/Apertus-8B", | ||
| dtype=torch.bfloat16, | ||
| device=0 | ||
| ) | ||
| pipeline("Plants create energy through a process known as") | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| <hfoption id="AutoModel"> | ||
|
|
||
| ```py | ||
| import torch | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained( | ||
| "swiss-ai/Apertus-8B", | ||
| ) | ||
| model = AutoModelForCausalLM.from_pretrained( | ||
| "swiss-ai/Apertus-8B", | ||
| dtype=torch.bfloat16, | ||
| device_map="auto", | ||
| attn_implementation="sdpa" | ||
| ) | ||
| input_ids = tokenizer("Plants create energy through a process known as", return_tensors="pt").to("cuda") | ||
|
|
||
| output = model.generate(**input_ids) | ||
| print(tokenizer.decode(output[0], skip_special_tokens=True)) | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| <hfoption id="transformers CLI"> | ||
|
|
||
| ```bash | ||
| echo -e "Plants create energy through a process known as" | transformers run --task text-generation --model swiss-ai/Apertus-8B --device 0 | ||
| ``` | ||
|
|
||
| </hfoption> | ||
| </hfoptions> | ||
|
|
||
| ## ApertusConfig | ||
|
|
||
| [[autodoc]] ApertusConfig | ||
|
|
||
| ## ApertusModel | ||
|
|
||
| [[autodoc]] ApertusModel | ||
| - forward | ||
|
|
||
| ## ApertusForCausalLM | ||
|
|
||
| [[autodoc]] ApertusForCausalLM | ||
| - forward | ||
|
|
||
| ## ApertusForTokenClassification | ||
|
|
||
| [[autodoc]] ApertusForTokenClassification | ||
| - forward |
This file contains hidden or 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 hidden or 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 @@ | ||
| # coding=utf-8 | ||
| # Copyright 2025 The HuggingFace Inc. team and the Swiss AI Initiative. All rights reserved. | ||
| # | ||
| # This code is based on HuggingFace's LLaMA implementation in this library. | ||
| # It has been modified from its original forms to accommodate the architectural | ||
| # differences made by the Swiss AI Initiative that trained the model. | ||
| # | ||
| # 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 _LazyModule | ||
| from ...utils.import_utils import define_import_structure | ||
|
|
||
|
|
||
| if TYPE_CHECKING: | ||
| from .configuration_apertus import * | ||
| from .modeling_apertus import * | ||
| else: | ||
| import sys | ||
|
|
||
| _file = globals()["__file__"] | ||
| sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__) |
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.
Uh oh!
There was an error while loading. Please reload this page.