-
Notifications
You must be signed in to change notification settings - Fork 27k
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
[WIP] Add diffllama #34083
Open
weak-kajuma
wants to merge
44
commits into
huggingface:main
Choose a base branch
from
weak-kajuma:add_diffllama
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.
+2,908
−1
Open
[WIP] Add diffllama #34083
Changes from 39 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
3bd9e34
first adding diffllama
weak-kajuma 269055e
add Diff Attention and other but still with errors
weak-kajuma dbbf073
complate make attention Diff-Attention
weak-kajuma c4ea9df
fix some bugs which may be caused by transformer-cli while adding model
weak-kajuma e072544
fix a bug caused by forgetting KV cache...
weak-kajuma 674d7a2
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 9eac636
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 0e99dbd
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 1e445c7
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma cca6a5c
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma dd167af
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 23099cb
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma faac378
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 53e13aa
I found Attention missed implemented from paper still on e072544a3bfc…
weak-kajuma 63b018a
re-implemented
weak-kajuma 204bec8
adding groupnorm
weak-kajuma bce12e5
align with transformers code style
weak-kajuma 44d8423
fix typo
weak-kajuma 6dc6f81
adding groupnorm
weak-kajuma 48b38e8
change SdpaAttention to DiffSdpaAttention
weak-kajuma 997f561
fix bug
weak-kajuma 107bd3c
Update src/transformers/models/diffllama/modeling_diffllama.py
weak-kajuma 26307d9
fix bugs of places of "GroupNorm with scale" and etc
weak-kajuma 22aa145
Revert "fix bugs of places of "GroupNorm with scale" and etc"
weak-kajuma cc472be
simplify multiple of attention (matmul) operations into one by repeat…
weak-kajuma e834129
simplify multiple of attention (matmul) operations into one by repeat…
weak-kajuma e9d94e5
simplify multiple of attention (matmul) operations into one by repeat…
weak-kajuma 0352999
remove missed type
weak-kajuma 843178a
add diffllama model_doc
weak-kajuma 71c8d12
apply make style/quality
weak-kajuma fea95fa
apply review comment about model
weak-kajuma b3f8dd5
apply review comment about test
weak-kajuma 50ce353
place diffllama alphabetically on the src/transformers/__init__.py
weak-kajuma 6f25333
fix forgot code
weak-kajuma dd2282e
Supports parameters that are not initialized with standard deviation …
weak-kajuma 9e7a9c3
add DiffLlamaConfig to CONFIG_CLASSES_TO_IGNORE_FOR_DOCSTRING_CHECKPO…
weak-kajuma 8c98d19
remove unused property of config
weak-kajuma cbf217d
add to supported model list
weak-kajuma c873982
add to spda supported model list
weak-kajuma b003a53
fix copyright, remove pretraining_tensor_parallel, and modify for ini…
weak-kajuma 37c7a88
remove unused import and etc.
weak-kajuma ba92d5c
empty commit
weak-kajuma 8cc823e
empty commit
weak-kajuma d47631d
empty commit
weak-kajuma 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,59 @@ | ||
<!--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. | ||
|
||
--> | ||
|
||
# DiffLlama | ||
|
||
## Overview | ||
|
||
The DiffLlama model was proposed in [Differential Transformer](https://arxiv.org/abs/2410.05258) by Kazuma Matsumoto and . | ||
This model is combine Llama model and Differential Transformer's Attention. | ||
|
||
The abstract from the paper is the following: | ||
|
||
*Transformer tends to overallocate attention to irrelevant context. In this work, we introduce Diff Transformer, which amplifies attention to the relevant context while canceling noise. Specifically, the differential attention mechanism calculates attention scores as the difference between two separate softmax attention maps. The subtraction cancels noise, promoting the emergence of sparse attention patterns. Experimental results on language modeling show that Diff Transformer outperforms Transformer in various settings of scaling up model size and training tokens. More intriguingly, it offers notable advantages in practical applications, such as long-context modeling, key information retrieval, hallucination mitigation, in-context learning, and reduction of activation outliers. By being less distracted by irrelevant context, Diff Transformer can mitigate hallucination in question answering and text summarization. For in-context learning, Diff Transformer not only enhances accuracy but is also more robust to order permutation, which was considered as a chronic robustness issue. The results position Diff Transformer as a highly effective and promising architecture to advance large language models.* | ||
|
||
### Usage tips | ||
The hyperparameters of this model is the same as Llama model. | ||
|
||
|
||
## DiffLlamaConfig | ||
|
||
[[autodoc]] DiffLlamaConfig | ||
|
||
## DiffLlamaModel | ||
|
||
[[autodoc]] DiffLlamaModel | ||
- forward | ||
|
||
## DiffLlamaForCausalLM | ||
|
||
[[autodoc]] DiffLlamaForCausalLM | ||
- forward | ||
|
||
## DiffLlamaForSequenceClassification | ||
|
||
[[autodoc]] DiffLlamaForSequenceClassification | ||
- forward | ||
|
||
## DiffLlamaForQuestionAnswering | ||
|
||
[[autodoc]] DiffLlamaForQuestionAnswering | ||
- forward | ||
|
||
## DiffLlamaForTokenClassification | ||
|
||
[[autodoc]] DiffLlamaForTokenClassification | ||
- 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 |
---|---|---|
|
@@ -71,6 +71,7 @@ | |
depth_anything, | ||
detr, | ||
dialogpt, | ||
diffllama, | ||
dinat, | ||
dinov2, | ||
distilbert, | ||
|
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,27 @@ | ||
# Copyright 2024 EleutherAI and The HuggingFace Inc. 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 _LazyModule | ||
from ...utils.import_utils import define_import_structure | ||
|
||
|
||
if TYPE_CHECKING: | ||
from .configuration_diffllama import * | ||
from .modeling_diffllama 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.
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.
Please check the company here, it is very likely wrong!