Text Generation
Transformers
Safetensors
English
deepseek_v3
instella
Mixture of Experts
amd
rocm
conversational
custom_code
text-generation-inference
Instructions to use amd/Instella-MoE-16B-A3B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use amd/Instella-MoE-16B-A3B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="amd/Instella-MoE-16B-A3B-Base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("amd/Instella-MoE-16B-A3B-Base", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("amd/Instella-MoE-16B-A3B-Base", trust_remote_code=True, device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use amd/Instella-MoE-16B-A3B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "amd/Instella-MoE-16B-A3B-Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amd/Instella-MoE-16B-A3B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/amd/Instella-MoE-16B-A3B-Base
- SGLang
How to use amd/Instella-MoE-16B-A3B-Base with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "amd/Instella-MoE-16B-A3B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amd/Instella-MoE-16B-A3B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "amd/Instella-MoE-16B-A3B-Base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "amd/Instella-MoE-16B-A3B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use amd/Instella-MoE-16B-A3B-Base with Docker Model Runner:
docker model run hf.co/amd/Instella-MoE-16B-A3B-Base
Release Instella-MoE-16B-A3B-Base
Browse files- .gitattributes +4 -0
- LICENSE +306 -0
- README.md +179 -0
- __init__.py +24 -0
- config.json +66 -0
- configuration_instella_moe.py +237 -0
- generation_config.json +9 -0
- images/fig_cost_performance.png +3 -0
- images/result_table_base_long.png +3 -0
- images/result_table_base_standard.png +3 -0
- images/result_table_instruct.png +3 -0
- merge_metadata.json +19 -0
- model-00000-of-00006.safetensors +3 -0
- model-00001-of-00006.safetensors +3 -0
- model-00002-of-00006.safetensors +3 -0
- model-00003-of-00006.safetensors +3 -0
- model-00004-of-00006.safetensors +3 -0
- model-00005-of-00006.safetensors +3 -0
- model.safetensors.index.json +0 -0
- modeling_instella_moe.py +397 -0
- special_tokens_map.json +23 -0
- tokenizer.json +0 -0
- tokenizer_config.json +35 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,7 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
images/fig_cost_performance.png filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
images/result_table_base_long.png filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
images/result_table_base_standard.png filter=lfs diff=lfs merge=lfs -text
|
| 39 |
+
images/result_table_instruct.png filter=lfs diff=lfs merge=lfs -text
|
LICENSE
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
RESEARCH-ONLY RAIL Model License
|
| 2 |
+
|
| 3 |
+
Section I: PREAMBLE
|
| 4 |
+
|
| 5 |
+
BY ACCESSING, DOWNLOADING, INSTALLING, OR USING THE ARTIFACT, YOU AGREE
|
| 6 |
+
TO BE BOUND BY THIS LICENSE. IF YOU DO NOT AGREE TO ALL OF THE TERMS AND
|
| 7 |
+
CONDITIONS OF THIS LICENSE, DO NOT ACCESS, DOWNLOAD, INSTALL, OR USE THE
|
| 8 |
+
ARTIFACT.
|
| 9 |
+
|
| 10 |
+
1. Definitions
|
| 11 |
+
|
| 12 |
+
(a) "Application" refers to a sequence of instructions or statements
|
| 13 |
+
written in machine code language, including object code (that is the
|
| 14 |
+
product of a compiler), binary code (data using a two-symbol system)
|
| 15 |
+
or an intermediate language (such as register transfer language).
|
| 16 |
+
|
| 17 |
+
(b) "Artifact" refers to a software application (in either binary or
|
| 18 |
+
source code format), Model, and/or Source Code that accompanies this
|
| 19 |
+
License.
|
| 20 |
+
|
| 21 |
+
(c) "Contribution" means any work, including any modifications or
|
| 22 |
+
additions to an Artifact, that is intentionally submitted to
|
| 23 |
+
Licensor for inclusion or incorporation in the Artifact directly or
|
| 24 |
+
indirectly by the rights owner. For the purposes of this definition,
|
| 25 |
+
"submitted" means any form of electronic, verbal, or written
|
| 26 |
+
communication sent to the Licensor or its representatives, including
|
| 27 |
+
but not limited to communication on electronic mailing lists, source
|
| 28 |
+
code control systems, and issue tracking systems that are managed
|
| 29 |
+
by, or on behalf of, the Licensor for the purpose of discussing,
|
| 30 |
+
sharing and improving the Artifact, but excluding communication that
|
| 31 |
+
is conspicuously marked or otherwise designated in writing by the
|
| 32 |
+
contributor as "Not a Contribution."
|
| 33 |
+
|
| 34 |
+
(d) "Contributor" means Licensor or any other individual or legal entity
|
| 35 |
+
that creates or owns a Contribution that is added to or incorporated
|
| 36 |
+
into an Artifact or its Derivative.
|
| 37 |
+
|
| 38 |
+
(e) "Data" means a collection of information and/or content extracted
|
| 39 |
+
from the dataset used with a given Model, including to train,
|
| 40 |
+
pretrain, or otherwise evaluate the Model. The Data is not licensed
|
| 41 |
+
under this License.
|
| 42 |
+
|
| 43 |
+
(f) "Derivative" means a work derived from or based upon an Artifact,
|
| 44 |
+
and includes all modified versions of such Artifact.
|
| 45 |
+
|
| 46 |
+
(g) "Distribution" means any transmission, reproduction, publication or
|
| 47 |
+
other sharing of an Artifact or Derivative to a Third Party,
|
| 48 |
+
including providing a hosted service incorporating the Artifact,
|
| 49 |
+
which is made available by electronic or other remote means -
|
| 50 |
+
e.g. API-based or web access.
|
| 51 |
+
|
| 52 |
+
(h) "Harm" includes but is not limited to physical, mental,
|
| 53 |
+
psychological, financial and reputational damage, pain, or loss.
|
| 54 |
+
|
| 55 |
+
(i) "License" means the terms and conditions for use, reproduction, and
|
| 56 |
+
Distribution as defined in this document.
|
| 57 |
+
|
| 58 |
+
(j) "Licensor" means the rights owner (by virtue of creation or
|
| 59 |
+
documented transfer of ownership) or entity authorized by the rights
|
| 60 |
+
owner (e.g., exclusive licensee) that is granting the rights in this
|
| 61 |
+
License.
|
| 62 |
+
|
| 63 |
+
(k) "Model" means any machine-learning based assembly or assemblies
|
| 64 |
+
(including checkpoints), consisting of learnt weights, parameters
|
| 65 |
+
(including optimizer states), corresponding to the model
|
| 66 |
+
architecture as embodied in the Source Code.
|
| 67 |
+
|
| 68 |
+
(l) "Output" means the results of operating a Model as embodied in
|
| 69 |
+
informational content resulting therefrom.
|
| 70 |
+
|
| 71 |
+
(m) "Permitted Purpose" means for academic or research purposes only.
|
| 72 |
+
|
| 73 |
+
(n) "Source Code" means any collection of text written using
|
| 74 |
+
human-readable programming language, including the code and scripts
|
| 75 |
+
used to define, run, load, benchmark or evaluate a Model or any
|
| 76 |
+
component thereof, and/or used to prepare data for training or
|
| 77 |
+
evaluation, if any. Source Code includes any accompanying
|
| 78 |
+
documentation, tutorials, examples, etc, if any. For clarity, the
|
| 79 |
+
term "Source Code" as used in this License includes any and all
|
| 80 |
+
Derivatives of such Source Code.
|
| 81 |
+
|
| 82 |
+
(o) "Third Party(ies)" means an individual or legal entity that is not
|
| 83 |
+
under common control with Licensor or You.
|
| 84 |
+
|
| 85 |
+
(p) "Use" includes accessing, using, copying, modifying, and/or
|
| 86 |
+
distributing an Artifact; in connection with a Model as Artifact,
|
| 87 |
+
Use also includes creating content, fine-tuning, updating, running,
|
| 88 |
+
training, evaluating and/or re-parametrizing such Model.
|
| 89 |
+
|
| 90 |
+
(q) "You" (or "Your") means an individual or legal entity receiving and
|
| 91 |
+
exercising permissions granted by this License and/or making use of
|
| 92 |
+
the Artifact for permitted purposes and in any permitted field of
|
| 93 |
+
use, including usage of the Artifact in an end-use application -
|
| 94 |
+
e.g. chatbot, translator, image generator, etc.
|
| 95 |
+
|
| 96 |
+
Section II: INTELLECTUAL PROPERTY RIGHTS
|
| 97 |
+
|
| 98 |
+
Both copyright and patent grants may apply to the Artifact. The Artifact
|
| 99 |
+
is subject to additional terms and conditions as described in Section III
|
| 100 |
+
below.
|
| 101 |
+
|
| 102 |
+
2. Grant of Copyright License. Conditioned upon compliance with Section
|
| 103 |
+
III below and subject to the terms and conditions of this License, each
|
| 104 |
+
Contributor hereby grants to You, only in connection with the Permitted
|
| 105 |
+
Purpose, a worldwide, non-exclusive, royalty-free copyright license to
|
| 106 |
+
reproduce, use, publicly display, publicly perform, sublicense, and
|
| 107 |
+
distribute the Artifact and Derivatives thereof.
|
| 108 |
+
|
| 109 |
+
3. Grant of Patent License. Conditioned upon compliance with Section III
|
| 110 |
+
below and subject to the terms and conditions of this License, and only
|
| 111 |
+
where and as applicable, each Contributor hereby grants to You, only in
|
| 112 |
+
connection with the Permitted Purpose, a worldwide, non-exclusive,
|
| 113 |
+
royalty-free, irrevocable (except as stated in this paragraph) patent
|
| 114 |
+
license to make, have made, use, sell, offer to sell, import, and
|
| 115 |
+
otherwise transfer the Artifact where such license applies only to those
|
| 116 |
+
patent claims licensable by such Contributor that are necessarily
|
| 117 |
+
infringed by their Contribution(s) alone or by combination of their
|
| 118 |
+
Contribution(s) with the Artifact to which such Contribution(s) was
|
| 119 |
+
submitted. If You institute patent litigation against any entity
|
| 120 |
+
(including a cross-claim or counterclaim in a lawsuit) alleging that the
|
| 121 |
+
Artifact and/or a Contribution incorporated within the Artifact
|
| 122 |
+
constitutes direct or contributory patent infringement, then any patent
|
| 123 |
+
licenses granted to You under this License in connection with the
|
| 124 |
+
Artifact shall terminate as of the date such litigation is asserted or
|
| 125 |
+
filed.
|
| 126 |
+
|
| 127 |
+
Section III: CONDITIONS OF USAGE, DISTRIBUTION AND REDISTRIBUTION
|
| 128 |
+
|
| 129 |
+
4. Use-based restrictions. The restrictions set forth in Attachment A are
|
| 130 |
+
mandatory Use-based restrictions. Therefore You may not Use the Artifact
|
| 131 |
+
in violation of such restrictions. You may Use the Artifact only subject
|
| 132 |
+
to this License. You shall require all of Your users who use the Artifact
|
| 133 |
+
or its Derivative to comply with the terms this License, including those
|
| 134 |
+
contained in this paragraph, and only for the Permitted Purpose.
|
| 135 |
+
|
| 136 |
+
5. The Output You Generate with a Model (as Artifact). Except as set
|
| 137 |
+
forth herein, Licensor claims no rights in the Output You generate. You
|
| 138 |
+
are accountable for the Output You generate and its subsequent uses. No
|
| 139 |
+
use of the Output may contravene any provision as stated in this
|
| 140 |
+
License.
|
| 141 |
+
|
| 142 |
+
6. Distribution and Redistribution. You may host for Third Party remote
|
| 143 |
+
access purposes (e.g. software-as-a-service), reproduce and distribute
|
| 144 |
+
copies of the Artifact or its Derivatives in any medium, with or without
|
| 145 |
+
modifications, provided that You meet the following conditions:
|
| 146 |
+
|
| 147 |
+
6.1. Use-based restrictions in paragraph 4 MUST be included as a
|
| 148 |
+
condition precedent to effect any type of legal agreement (e.g. a
|
| 149 |
+
license) governing the use and/or distribution of the Artifact or
|
| 150 |
+
its Derivatives, and You shall give such notice to any subsequent
|
| 151 |
+
Third Party recipients;
|
| 152 |
+
6.2. You shall give any Third Party recipients of the Artifact or its
|
| 153 |
+
Derivatives a copy of this License;
|
| 154 |
+
6.3. You shall cause any modified files to carry prominent notices
|
| 155 |
+
stating that You changed the files;
|
| 156 |
+
6.4. You shall retain all copyright, patent, trademark, and attribution
|
| 157 |
+
notices excluding those notices that do not pertain to any part of
|
| 158 |
+
the Artifact or its Derivatives.
|
| 159 |
+
6.5. You and any Third Party recipients of the Artifact or its
|
| 160 |
+
Derivative shall adhere to the Permitted Purpose.
|
| 161 |
+
|
| 162 |
+
You may add Your own copyright statement to Your modifications and may
|
| 163 |
+
provide additional or different license terms and conditions with
|
| 164 |
+
respect to paragraph 6.1., to govern the use, reproduction, or
|
| 165 |
+
Distribution of Your modifications, or for any Derivative, provided that
|
| 166 |
+
Your use, reproduction, and Distribution of the Artifact or its
|
| 167 |
+
Derivative otherwise complies with the conditions stated in this
|
| 168 |
+
License. In other words, the Use-based restrictions in Attachment A form
|
| 169 |
+
the minimum set of terms for You to license to Third Parties any
|
| 170 |
+
Artifact or its Derivative, but You may add more restrictive terms if
|
| 171 |
+
You deem it necessary.
|
| 172 |
+
|
| 173 |
+
Section IV: OTHER PROVISIONS
|
| 174 |
+
|
| 175 |
+
7. Updates and Runtime Restrictions. To the maximum extent permitted by
|
| 176 |
+
law, Licensor reserves the right to restrict (remotely or otherwise)
|
| 177 |
+
usage of the Artifact in violation of this License or update the
|
| 178 |
+
Artifact through electronic means.
|
| 179 |
+
|
| 180 |
+
8. Trademarks and Related. Nothing in this License permits You to make
|
| 181 |
+
use of trademarks, trade names, or logos of the Licensor or a
|
| 182 |
+
Contributor, or to otherwise suggest an endorsement or misrepresent the
|
| 183 |
+
relationship between You and the Licensor (or a Contributor); any rights
|
| 184 |
+
not expressly granted herein are reserved.
|
| 185 |
+
|
| 186 |
+
9. Disclaimer of Warranty. Unless required by applicable law or agreed
|
| 187 |
+
to in writing, Licensor provides the Artifact (and each Contributor
|
| 188 |
+
provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
| 189 |
+
CONDITIONS OF ANY KIND, either express or implied, including, without
|
| 190 |
+
limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT,
|
| 191 |
+
MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely
|
| 192 |
+
responsible for determining the appropriateness of using the Artifact,
|
| 193 |
+
and assume any risks associated with Your exercise of permissions under
|
| 194 |
+
this License.
|
| 195 |
+
|
| 196 |
+
10. Limitation of Liability. In no event and under no legal theory,
|
| 197 |
+
whether in tort (including negligence), contract, or otherwise, unless
|
| 198 |
+
required by applicable law (such as deliberate and grossly negligent
|
| 199 |
+
acts) or agreed to in writing, shall any Contributor be liable to You
|
| 200 |
+
for damages, including any direct, indirect, special, incidental, or
|
| 201 |
+
consequential damages of any character arising as a result of this
|
| 202 |
+
License or out of the use or inability to use the Artifact (including
|
| 203 |
+
but not limited to damages for loss of goodwill, work stoppage, computer
|
| 204 |
+
failure or malfunction, or any and all other commercial damages or
|
| 205 |
+
losses), even if such Contributor has been advised of the possibility of
|
| 206 |
+
such damages.
|
| 207 |
+
|
| 208 |
+
11. If any provision of this License is held to be invalid, illegal or
|
| 209 |
+
unenforceable, the remaining provisions shall be unaffected thereby and
|
| 210 |
+
remain valid as if such provision had not been set forth herein.
|
| 211 |
+
|
| 212 |
+
12. Term and Termination. The term of this License will commence upon
|
| 213 |
+
the earlier of Your (a) acceptance of this License or (b) accessing the
|
| 214 |
+
Artifact; and will continue in full force and effect until terminated in
|
| 215 |
+
accordance with the terms and conditions herein. Licensor may terminate
|
| 216 |
+
this License if You are in breach of any term or condition of this
|
| 217 |
+
License. Upon termination of this License, all licenses granted to You
|
| 218 |
+
will terminate and You must promptly delete and cease use of the
|
| 219 |
+
Artifact. Sections 1, 7, 8, 9, 10, 11, and 12 survive termination of
|
| 220 |
+
this License.
|
| 221 |
+
|
| 222 |
+
END OF TERMS AND CONDITIONS
|
| 223 |
+
|
| 224 |
+
Attachment A
|
| 225 |
+
|
| 226 |
+
AMD Responsible AI Use Policy
|
| 227 |
+
|
| 228 |
+
AMD is committed to the responsible use of its Artificial Intelligence
|
| 229 |
+
(AI) products and technologies ("AMD AI"). AMD AI may include
|
| 230 |
+
artificial intelligence or machine learning technologies that use
|
| 231 |
+
algorithms to analyze data and generate output using predictions based
|
| 232 |
+
on patterns in data. This policy explains the uses that AMD
|
| 233 |
+
specifically prohibits.
|
| 234 |
+
|
| 235 |
+
If you use any AMD AI, you are agreeing to use
|
| 236 |
+
the AMD AI in compliance with applicable laws and not for any of the
|
| 237 |
+
following prohibited uses.
|
| 238 |
+
|
| 239 |
+
Prohibited Uses:
|
| 240 |
+
|
| 241 |
+
1) No Illegal Acts. Do not use AMD AI in violation of any applicable
|
| 242 |
+
national, state, local, or other jurisdictional law, rule, regulation,
|
| 243 |
+
or sanction.
|
| 244 |
+
|
| 245 |
+
2) No Explicit Content. Do not use AMD AI to submit (as input),
|
| 246 |
+
generate, or disseminate content depicting violent or sexually explicit
|
| 247 |
+
content or to create sexual chatbots.
|
| 248 |
+
|
| 249 |
+
3) No Harm. Do not use AMD AI for any potentially harmful uses,
|
| 250 |
+
including fraud, deception, bias and discrimination, abuse, or harassment,
|
| 251 |
+
including the following:
|
| 252 |
+
|
| 253 |
+
a) Harm or abuse of a minor, including grooming and child sexual
|
| 254 |
+
exploitation.
|
| 255 |
+
|
| 256 |
+
b) Impersonation of human beings for purposes of deception.
|
| 257 |
+
|
| 258 |
+
c) Generation or dissemination of information you know to be false
|
| 259 |
+
for the purpose of harming others.
|
| 260 |
+
|
| 261 |
+
d) Intentionally defame, disparage, or otherwise harass others.
|
| 262 |
+
|
| 263 |
+
e) Intentionally attempting to materially distort the behavior of a
|
| 264 |
+
person in a manner that causes or is likely to cause that person
|
| 265 |
+
or another person physical or psychological harm.
|
| 266 |
+
|
| 267 |
+
f) Providing medical advice or interpretation of medical results that
|
| 268 |
+
is intended to be a substitute for professional medical advice,
|
| 269 |
+
diagnosis, or treatment.
|
| 270 |
+
|
| 271 |
+
g) Engaging in the unlawful or unauthorized practice of any
|
| 272 |
+
profession, including financial, legal, medical, health, or
|
| 273 |
+
related professional practices.
|
| 274 |
+
|
| 275 |
+
h) Judgment of, discrimination against, or harm to individuals or
|
| 276 |
+
groups based on legally protected characteristics or categories,
|
| 277 |
+
online or offline social behavior, or known or predicted personal
|
| 278 |
+
or personality characteristics, including any of the foregoing
|
| 279 |
+
uses in social credit systems.
|
| 280 |
+
|
| 281 |
+
4) No High-Risk Activity. Do not use AMD AI in any high-risk activities
|
| 282 |
+
or applications that create risk of harm to individuals health, safety
|
| 283 |
+
or fundamental rights or to safety of critical infrastructure or
|
| 284 |
+
environmental damage, including in weapons or military applications.
|
| 285 |
+
|
| 286 |
+
5) No Personal Information. Do not use AMD AI to collect, process, or
|
| 287 |
+
disclose personal data, including heath or sensitive personal
|
| 288 |
+
information, without the necessary rights or consents.
|
| 289 |
+
|
| 290 |
+
6) No Infringement. Do not use AMD AI to generate or disseminate any
|
| 291 |
+
information that infringes upon or misappropriates the intellectual
|
| 292 |
+
property rights of others, including copyright, trademark, patent, and
|
| 293 |
+
trade secret rights, rights to privacy, and publicity rights.
|
| 294 |
+
|
| 295 |
+
7) No Malware. Do not use AMD AI to generate or disseminate malware or
|
| 296 |
+
any other content to be used for the purpose of facilitating unpermitted
|
| 297 |
+
access to, or use of, computer systems or data.
|
| 298 |
+
|
| 299 |
+
8) No Obfuscation. Do not inappropriately obfuscate or fail to disclose
|
| 300 |
+
to end users the presence of AI in any application in which AMD AI is
|
| 301 |
+
deployed, along with any known risks or dangers of using AI without
|
| 302 |
+
appropriate safeguards, oversight and human control.
|
| 303 |
+
|
| 304 |
+
9) No Reliance. Do not rely on any information generated using AMD AI
|
| 305 |
+
without assessing it for accuracy, potential for harm, or other specific
|
| 306 |
+
risks applicable to the use case.
|
README.md
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: researchrail
|
| 4 |
+
license_link: LICENSE
|
| 5 |
+
pipeline_tag: text-generation
|
| 6 |
+
library_name: transformers
|
| 7 |
+
language:
|
| 8 |
+
- en
|
| 9 |
+
tags:
|
| 10 |
+
- instella
|
| 11 |
+
- moe
|
| 12 |
+
- amd
|
| 13 |
+
- rocm
|
| 14 |
+
---
|
| 15 |
+
|
| 16 |
+
<div align="center">
|
| 17 |
+
<br>
|
| 18 |
+
<br>
|
| 19 |
+
|
| 20 |
+
<h1>Instella-MoE✨: Fully Open State-of-the-Art Mixture-of-Experts Language Model</h1>
|
| 21 |
+
<a href='https://huggingface.co/collections/amd/instella-moe'><img src='https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Model-blue'></a>
|
| 22 |
+
<a href='https://rocm.blogs.amd.com/artificial-intelligence/instella-moe/README.html'><img src='https://img.shields.io/badge/Technical-Blog-red'></a>
|
| 23 |
+
<a href='https://github.com/AMD-AGI/Instella-MoE'><img src='https://img.shields.io/badge/GitHub-Code-black?logo=github'></a>
|
| 24 |
+
|
| 25 |
+
</div>
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
Instella-MoE is a state-of-the-art fully open Mixture-of-Experts (MoE) language model with 16 billion total parameters and 2.8 billion active parameters trained end-to-end from pre-training to RL.
|
| 29 |
+
Trained from scratch on AMD Instinct™ MI300X and MI325X GPUs using AMD's Primus framework, Instella-MoE combines a sparsely activated MoE design with architectural innovations such as Gated Multi-head Latent Attention (Gated MLA) and [FarSkip-Collective](https://github.com/AMD-AGI/FarSkip-Collective).
|
| 30 |
+
|
| 31 |
+
<div align="center">
|
| 32 |
+
<img src="images/fig_cost_performance.png" alt="Instella-MoE cost vs. performance" width="720"/>
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
+
*Figure 1: Pre-trained and Post-trained Instella-MoE model performance compared with other similar size state-of-the-art models.*
|
| 36 |
+
|
| 37 |
+
## Takeaways
|
| 38 |
+
|
| 39 |
+
- Instella-MoE is a new state-of-the-art fully open Mixture-of-Experts language model developed by AMD, with 16 billion total parameters and 2.8 billion active parameters per token, trained from scratch on AMD Instinct™ MI300X and MI325X GPUs.
|
| 40 |
+
- The Instella-MoE model checkpoint release spans every stage of the model training pipeline, including pre-training, mid-training, long-context extension, SFT, DPO and RL.
|
| 41 |
+
- Built entirely on the AMD ROCm™ software stack on top of the Primus training and Miles RL frameworks, Instella-MoE incorporates cutting-edge architecture and systems innovations—including Gated Multi-head Latent Attention (Gated MLA) and extreme communication-computation overlap through FarSkip-Collective—for efficient large-scale training and inference on AMD hardware.
|
| 42 |
+
- Fully open and accessible: we provide our complete training recipe across all training stages, including training frameworks, data mixtures, intermediate checkpoints and inference code.
|
| 43 |
+
|
| 44 |
+
The release includes checkpoints from the following Instella-MoE training pipeline stages as shown in Table 1 below:
|
| 45 |
+
|
| 46 |
+
| Model | Stage | Description |
|
| 47 |
+
| ----- | ----- | ----------- |
|
| 48 |
+
| Instella-MoE-16B-A3B-Pretrain ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-Pretrain)) | Pre-training | MoE base model trained from scratch on a large and diverse training corpus. |
|
| 49 |
+
| Instella-MoE-16B-A3B-Midtrain ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-Midtrain)) | Mid-training | Pretrained model further trained on high-quality data mixtures to refine key capabilities. |
|
| 50 |
+
| Instella-MoE-16B-A3B-Base ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-Base)) | Long-context | Long-context training to extend the model’s ability to process and reason over longer sequences. **We use this as our final base checkpoint**. |
|
| 51 |
+
| Instella-MoE-16B-A3B-SFT ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-SFT)) | SFT | Base checkpoint extended via supervised fine-tuning (SFT) to enable instruction following and chain-of-thought reasoning capabilities. |
|
| 52 |
+
| Instella-MoE-16B-A3B-DPO ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-DPO)) | DPO | Direct preference optimization (DPO) on contrastive preference data to improve model performance. |
|
| 53 |
+
| Instella-MoE-16B-A3B-Think ([Link](https://huggingface.co/amd/Instella-MoE-16B-A3B-Think)) | RL | Final thinking checkpoint refined with reinforcement learning (RL) to further strengthen instruction following and overall response quality. |
|
| 54 |
+
|
| 55 |
+
<em><strong>Table 1:</strong> Instella-MoE-16B-A3B models and training stages.</em>
|
| 56 |
+
|
| 57 |
+
### Model Summary
|
| 58 |
+
|
| 59 |
+
| Parameter | Value |
|
| 60 |
+
| :---- | :---- |
|
| 61 |
+
| Total Parameters | 16B |
|
| 62 |
+
| Active Parameters per Token | 2.8B |
|
| 63 |
+
| Decoder Layers | 27 |
|
| 64 |
+
| Hidden Size | 2048 |
|
| 65 |
+
| Attention Heads | 16 |
|
| 66 |
+
| Number of Experts | 64 |
|
| 67 |
+
| Shared Experts | 2 |
|
| 68 |
+
| Activated Experts per Token | 6 |
|
| 69 |
+
| Vocabulary Size | 128,896 |
|
| 70 |
+
| Attention | Gated Multi-head Latent Attention (Gated MLA) |
|
| 71 |
+
| MoE Connectivity | FarSkip-Collective |
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
## Results
|
| 75 |
+
|
| 76 |
+
### Pretraining Results
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
<div align="center">
|
| 80 |
+
<img src="images/result_table_base_standard.png" alt="Base results on standard benchmarks" width="900"/>
|
| 81 |
+
</div>
|
| 82 |
+
|
| 83 |
+
*Table 2: Instella-MoE-16B-A3B-Base Results on Standard Benchmarks.*
|
| 84 |
+
|
| 85 |
+
<div align="center">
|
| 86 |
+
<img src="images/result_table_base_long.png" alt="Base results on long-context benchmarks" width="900"/>
|
| 87 |
+
</div>
|
| 88 |
+
|
| 89 |
+
*Table 3: Instella-MoE-16B-A3B-Base Results on Long Context HELMET and RULER Benchmarks.*
|
| 90 |
+
|
| 91 |
+
### Post-training Results
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
<div align="center">
|
| 95 |
+
<img src="images/result_table_instruct.png" alt="Instella-MoE-Think post-training results" width="900"/>
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
*Table 4: Instella-MoE-Think results. We evaluate all models using the OLMES framework, generating up to a maximum of 32768 tokens.*
|
| 99 |
+
|
| 100 |
+
## Getting Started
|
| 101 |
+
|
| 102 |
+
### Example Usage
|
| 103 |
+
```python
|
| 104 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 105 |
+
checkpoint = "amd/Instella-MoE-16B-A3B-Think"
|
| 106 |
+
|
| 107 |
+
tokenizer = AutoTokenizer.from_pretrained(checkpoint, trust_remote_code=True)
|
| 108 |
+
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", trust_remote_code=True)
|
| 109 |
+
|
| 110 |
+
prompt = [{"role": "user", "content": "What are the computational benefits of Mixture-of-Experts models?"}]
|
| 111 |
+
inputs = tokenizer.apply_chat_template(
|
| 112 |
+
prompt,
|
| 113 |
+
add_generation_prompt=True,
|
| 114 |
+
return_tensors='pt'
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
tokens = model.generate(
|
| 118 |
+
inputs.to(model.device),
|
| 119 |
+
max_new_tokens=1024,
|
| 120 |
+
temperature=0.8,
|
| 121 |
+
do_sample=True
|
| 122 |
+
)
|
| 123 |
+
|
| 124 |
+
print(tokenizer.decode(tokens[0], skip_special_tokens=False))
|
| 125 |
+
```
|
| 126 |
+
For high-throughput inference with [SGLang](https://github.com/sgl-project/sglang), please refer to the setup and usage instructions in our [GitHub repository](https://github.com/AMD-AGI/Instella-MoE).
|
| 127 |
+
|
| 128 |
+
## Training Details
|
| 129 |
+
|
| 130 |
+
Instella-MoE was trained end-to-end on AMD Instinct™ MI300X and MI325X GPUs using the AMD ROCm™ software stack, built on top of the [Primus](https://github.com/AMD-AGI/Primus) training framework and the [Miles](https://github.com/radixark/miles) RL framework. Training proceeds through a multi-stage pipeline—pre-training, mid-training, long-context extension, SFT, DPO, and RL—with each stage progressively strengthening the model's capabilities.
|
| 131 |
+
|
| 132 |
+
For the complete training recipe, including per-stage data mixtures, hyperparameters, training frameworks, and inference code, please refer to our [GitHub repository](https://github.com/AMD-AGI/Instella-MoE) and [technical blog](https://rocm.blogs.amd.com/artificial-intelligence/instella-moe/README.html).
|
| 133 |
+
|
| 134 |
+
## Acknowledgements
|
| 135 |
+
|
| 136 |
+
We are deeply grateful to the LLM360 team and the Miles team for their invaluable support throughout the development of our model.
|
| 137 |
+
|
| 138 |
+
## License
|
| 139 |
+
|
| 140 |
+
- The Instella-MoE models are licensed for academic and research purposes under a ResearchRAIL license.
|
| 141 |
+
- Refer to the [LICENSE](./LICENSE) for more information.
|
| 142 |
+
|
| 143 |
+
## Bias, Risks, and Limitations
|
| 144 |
+
|
| 145 |
+
- The models are being released for research purposes only. They are not intended for use cases requiring high levels of factual accuracy, safety-critical applications, or health and medical applications. They must not be used to generate false information or facilitate toxic conversations.
|
| 146 |
+
- Model checkpoints are made accessible without any safety promises. It is crucial for users to conduct comprehensive evaluations and implement safety filtering mechanisms as per their respective use cases.
|
| 147 |
+
- It may be possible to prompt the model to generate content that may be factually inaccurate, harmful, violent, toxic, biased, or otherwise objectionable. Such content may also be generated in response to prompts that were not intended to elicit it. Users are thus requested to be aware of this and exercise caution and responsible thinking when using the model.
|
| 148 |
+
- The multilingual abilities of the models have not been tested and thus may misunderstand and generate erroneous responses across different languages.
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
## Contributors
|
| 152 |
+
|
| 153 |
+
> **Core contributors**:
|
| 154 |
+
> Jiang Liu, Sudhanshu Ranjan, Prakamya Mishra, Yonatan Dukler, Gowtham Ramesh, Zicheng Liu
|
| 155 |
+
>
|
| 156 |
+
> **Contributors:**
|
| 157 |
+
> Jialian Wu, Ximeng Sun, Wen Xie, Chaojun Hou, Vikram Appia, Zhenyu Gu, Emad Barsoum
|
| 158 |
+
|
| 159 |
+
## Citations
|
| 160 |
+
|
| 161 |
+
Instella-MoE technical report is coming soon. In the meantime feel free to cite:
|
| 162 |
+
|
| 163 |
+
```text
|
| 164 |
+
@article{instella,
|
| 165 |
+
title={Instella: Fully Open Language Models with Stellar Performance},
|
| 166 |
+
author={Liu, Jiang and Wu, Jialian and Yu, Xiaodong and Su, Yusheng and Mishra, Prakamya and Ramesh, Gowtham and Ranjan, Sudhanshu and Manem, Chaitanya and Sun, Ximeng and Wang, Ze and Brahma, Pratik Prabhanjan and Liu, Zicheng and Barsoum, Emad},
|
| 167 |
+
journal={arXiv preprint arXiv:2511.10628},
|
| 168 |
+
year={2025}
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
@inproceedings{
|
| 172 |
+
dukler2026farskipcollective,
|
| 173 |
+
title={FarSkip-Collective: Unhobbling Blocking Communication in Mixture of Experts Models},
|
| 174 |
+
author={Yonatan Dukler and Guihong Li and Deval Shah and Jiang Liu and Vikram Appia and Emad Barsoum},
|
| 175 |
+
booktitle={Ninth Conference on Machine Learning and Systems},
|
| 176 |
+
year={2026},
|
| 177 |
+
url={https://openreview.net/forum?id=ruOpvLzsGV}
|
| 178 |
+
}
|
| 179 |
+
```
|
__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TYPE_CHECKING
|
| 2 |
+
|
| 3 |
+
from transformers.utils import _LazyModule
|
| 4 |
+
|
| 5 |
+
_import_structure = {
|
| 6 |
+
"configuration_instella_moe": ["InstellaMoEConfig"],
|
| 7 |
+
"modeling_instella_moe": [
|
| 8 |
+
"InstellaMoEForCausalLM",
|
| 9 |
+
"InstellaMoEModel",
|
| 10 |
+
"InstellaMoEPreTrainedModel",
|
| 11 |
+
],
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
if TYPE_CHECKING:
|
| 15 |
+
from .configuration_instella_moe import InstellaMoEConfig
|
| 16 |
+
from .modeling_instella_moe import (
|
| 17 |
+
InstellaMoEForCausalLM,
|
| 18 |
+
InstellaMoEModel,
|
| 19 |
+
InstellaMoEPreTrainedModel,
|
| 20 |
+
)
|
| 21 |
+
else:
|
| 22 |
+
import sys
|
| 23 |
+
|
| 24 |
+
sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure)
|
config.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"architectures": [
|
| 3 |
+
"InstellaMoEForCausalLM"
|
| 4 |
+
],
|
| 5 |
+
"attention_bias": false,
|
| 6 |
+
"farskip": true,
|
| 7 |
+
"attention_dropout": 0.0,
|
| 8 |
+
"auto_map": {
|
| 9 |
+
"AutoConfig": "configuration_instella_moe.InstellaMoEConfig",
|
| 10 |
+
"AutoModel": "modeling_instella_moe.InstellaMoEModel",
|
| 11 |
+
"AutoModelForCausalLM": "modeling_instella_moe.InstellaMoEForCausalLM"
|
| 12 |
+
},
|
| 13 |
+
"aux_loss_alpha": 0.001,
|
| 14 |
+
"bos_token_id": 1,
|
| 15 |
+
"eos_token_id": 2,
|
| 16 |
+
"ep_size": 1,
|
| 17 |
+
"first_k_dense_replace": 1,
|
| 18 |
+
"gated_attention": true,
|
| 19 |
+
"hidden_act": "silu",
|
| 20 |
+
"hidden_size": 2048,
|
| 21 |
+
"initializer_range": 0.02,
|
| 22 |
+
"intermediate_size": 10944,
|
| 23 |
+
"kv_lora_rank": 512,
|
| 24 |
+
"qk_layernorm": true,
|
| 25 |
+
"max_position_embeddings": 65536,
|
| 26 |
+
"model_type": "deepseek_v3",
|
| 27 |
+
"moe_intermediate_size": 1408,
|
| 28 |
+
"moe_layer_freq": 1,
|
| 29 |
+
"n_group": 1,
|
| 30 |
+
"n_routed_experts": 64,
|
| 31 |
+
"n_shared_experts": 2,
|
| 32 |
+
"norm_topk_prob": true,
|
| 33 |
+
"num_attention_heads": 16,
|
| 34 |
+
"num_experts_per_tok": 6,
|
| 35 |
+
"num_hidden_layers": 27,
|
| 36 |
+
"num_key_value_heads": 16,
|
| 37 |
+
"num_nextn_predict_layers": 1,
|
| 38 |
+
"q_lora_rank": null,
|
| 39 |
+
"pretraining_tp": 1,
|
| 40 |
+
"qk_head_dim": 128,
|
| 41 |
+
"qk_nope_head_dim": 96,
|
| 42 |
+
"qk_rope_head_dim": 32,
|
| 43 |
+
"rope_interleave": true,
|
| 44 |
+
"rms_norm_eps": 1e-06,
|
| 45 |
+
"rope_scaling": {
|
| 46 |
+
"beta_fast": 32,
|
| 47 |
+
"beta_slow": 1,
|
| 48 |
+
"factor": 40,
|
| 49 |
+
"mscale": 1.0,
|
| 50 |
+
"mscale_all_dim": 1.0,
|
| 51 |
+
"original_max_position_embeddings": 4096,
|
| 52 |
+
"type": "yarn"
|
| 53 |
+
},
|
| 54 |
+
"rope_theta": 8000000,
|
| 55 |
+
"routed_scaling_factor": 2.5,
|
| 56 |
+
"scoring_func": "sigmoid",
|
| 57 |
+
"seq_aux": true,
|
| 58 |
+
"tie_word_embeddings": false,
|
| 59 |
+
"topk_group": 1,
|
| 60 |
+
"topk_method": "noaux_tc",
|
| 61 |
+
"torch_dtype": "bfloat16",
|
| 62 |
+
"transformers_version": "4.57.1",
|
| 63 |
+
"use_cache": true,
|
| 64 |
+
"v_head_dim": 128,
|
| 65 |
+
"vocab_size": 128896
|
| 66 |
+
}
|
configuration_instella_moe.py
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from transformers.configuration_utils import PretrainedConfig
|
| 2 |
+
from transformers.utils import logging
|
| 3 |
+
|
| 4 |
+
logger = logging.get_logger(__name__)
|
| 5 |
+
|
| 6 |
+
DEEPSEEK_PRETRAINED_CONFIG_ARCHIVE_MAP = {}
|
| 7 |
+
class InstellaMoEConfig(PretrainedConfig):
|
| 8 |
+
r"""
|
| 9 |
+
This is the configuration class to store the configuration of a [`InstellaMoEModel`]. It is used to instantiate an DeepSeek
|
| 10 |
+
model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
|
| 11 |
+
defaults will yield a similar configuration to that of the DeepSeek-V3.
|
| 12 |
+
|
| 13 |
+
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
|
| 14 |
+
documentation from [`PretrainedConfig`] for more information.
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
Args:
|
| 18 |
+
vocab_size (`int`, *optional*, defaults to 129280):
|
| 19 |
+
Vocabulary size of the Deep model. Defines the number of different tokens that can be represented by the
|
| 20 |
+
`inputs_ids` passed when calling [`InstellaMoEModel`]
|
| 21 |
+
hidden_size (`int`, *optional*, defaults to 4096):
|
| 22 |
+
Dimension of the hidden representations.
|
| 23 |
+
intermediate_size (`int`, *optional*, defaults to 11008):
|
| 24 |
+
Dimension of the MLP representations.
|
| 25 |
+
moe_intermediate_size (`int`, *optional*, defaults to 1407):
|
| 26 |
+
Dimension of the MoE representations.
|
| 27 |
+
num_hidden_layers (`int`, *optional*, defaults to 32):
|
| 28 |
+
Number of hidden layers in the Transformer decoder.
|
| 29 |
+
num_nextn_predict_layers (`int`, *optional*, defaults to 1):
|
| 30 |
+
Number of nextn predict layers in the InstellaMoE Model.
|
| 31 |
+
num_attention_heads (`int`, *optional*, defaults to 32):
|
| 32 |
+
Number of attention heads for each attention layer in the Transformer decoder.
|
| 33 |
+
n_shared_experts (`int`, *optional*, defaults to None):
|
| 34 |
+
Number of shared experts, None means dense model.
|
| 35 |
+
n_routed_experts (`int`, *optional*, defaults to None):
|
| 36 |
+
Number of routed experts, None means dense model.
|
| 37 |
+
routed_scaling_factor (`float`, *optional*, defaults to 1.0):
|
| 38 |
+
Scaling factor or routed experts.
|
| 39 |
+
topk_method (`str`, *optional*, defaults to `gready`):
|
| 40 |
+
Topk method used in routed gate.
|
| 41 |
+
n_group (`int`, *optional*, defaults to None):
|
| 42 |
+
Number of groups for routed experts.
|
| 43 |
+
topk_group (`int`, *optional*, defaults to None):
|
| 44 |
+
Number of selected groups for each token(for each token, ensuring the selected experts is only within `topk_group` groups).
|
| 45 |
+
num_experts_per_tok (`int`, *optional*, defaults to None):
|
| 46 |
+
Number of selected experts, None means dense model.
|
| 47 |
+
moe_layer_freq (`int`, *optional*, defaults to 1):
|
| 48 |
+
The frequency of the MoE layer: one expert layer for every `moe_layer_freq - 1` dense layers.
|
| 49 |
+
first_k_dense_replace (`int`, *optional*, defaults to 0):
|
| 50 |
+
Number of dense layers in shallow layers(embed->dense->dense->...->dense->moe->moe...->lm_head).
|
| 51 |
+
\--k dense layers--/
|
| 52 |
+
norm_topk_prob (`bool`, *optional*, defaults to False):
|
| 53 |
+
Whether to normalize the weights of the routed experts.
|
| 54 |
+
scoring_func (`str`, *optional*, defaults to 'softmax'):
|
| 55 |
+
Method of computing expert weights.
|
| 56 |
+
aux_loss_alpha (`float`, *optional*, defaults to 0.001):
|
| 57 |
+
Auxiliary loss weight coefficient.
|
| 58 |
+
seq_aux = (`bool`, *optional*, defaults to True):
|
| 59 |
+
Whether to compute the auxiliary loss for each individual sample.
|
| 60 |
+
num_key_value_heads (`int`, *optional*):
|
| 61 |
+
This is the number of key_value heads that should be used to implement Grouped Query Attention. If
|
| 62 |
+
`num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
|
| 63 |
+
`num_key_value_heads=1 the model will use Multi Query Attention (MQA) otherwise GQA is used. When
|
| 64 |
+
converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
|
| 65 |
+
by meanpooling all the original heads within that group. For more details checkout [this
|
| 66 |
+
paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to
|
| 67 |
+
`num_attention_heads`.
|
| 68 |
+
hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
|
| 69 |
+
The non-linear activation function (function or string) in the decoder.
|
| 70 |
+
max_position_embeddings (`int`, *optional*, defaults to 2048):
|
| 71 |
+
The maximum sequence length that this model might ever be used with.
|
| 72 |
+
initializer_range (`float`, *optional*, defaults to 0.02):
|
| 73 |
+
The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
|
| 74 |
+
rms_norm_eps (`float`, *optional*, defaults to 1e-06):
|
| 75 |
+
The epsilon used by the rms normalization layers.
|
| 76 |
+
use_cache (`bool`, *optional*, defaults to `True`):
|
| 77 |
+
Whether or not the model should return the last key/values attentions (not used by all models). Only
|
| 78 |
+
relevant if `config.is_decoder=True`.
|
| 79 |
+
pad_token_id (`int`, *optional*):
|
| 80 |
+
Padding token id.
|
| 81 |
+
bos_token_id (`int`, *optional*, defaults to 1):
|
| 82 |
+
Beginning of stream token id.
|
| 83 |
+
eos_token_id (`int`, *optional*, defaults to 2):
|
| 84 |
+
End of stream token id.
|
| 85 |
+
pretraining_tp (`int`, *optional*, defaults to 1):
|
| 86 |
+
Experimental feature. Tensor parallelism rank used during pretraining. Please refer to [this
|
| 87 |
+
document](https://huggingface.co/docs/transformers/parallelism) to understand more about it. This value is
|
| 88 |
+
necessary to ensure exact reproducibility of the pretraining results. Please refer to [this
|
| 89 |
+
issue](https://github.com/pytorch/pytorch/issues/76232).
|
| 90 |
+
tie_word_embeddings (`bool`, *optional*, defaults to `False`):
|
| 91 |
+
Whether to tie weight embeddings
|
| 92 |
+
rope_theta (`float`, *optional*, defaults to 10000.0):
|
| 93 |
+
The base period of the RoPE embeddings.
|
| 94 |
+
rope_scaling (`Dict`, *optional*):
|
| 95 |
+
Dictionary containing the scaling configuration for the RoPE embeddings. Currently supports two scaling
|
| 96 |
+
strategies: linear and dynamic. Their scaling factor must be a float greater than 1. The expected format is
|
| 97 |
+
`{"type": strategy name, "factor": scaling factor}`. When using this flag, don't update
|
| 98 |
+
`max_position_embeddings` to the expected new maximum.
|
| 99 |
+
attention_bias (`bool`, defaults to `False`, *optional*, defaults to `False`):
|
| 100 |
+
Whether to use a bias in the query, key, value and output projection layers during self-attention.
|
| 101 |
+
attention_dropout (`float`, *optional*, defaults to 0.0):
|
| 102 |
+
The dropout ratio for the attention probabilities.
|
| 103 |
+
|
| 104 |
+
```python
|
| 105 |
+
>>> from transformers import InstellaMoEModel, InstellaMoEConfig
|
| 106 |
+
|
| 107 |
+
>>> # Initializing a Deepseek-V3 style configuration
|
| 108 |
+
>>> configuration = InstellaMoEConfig()
|
| 109 |
+
|
| 110 |
+
>>> # Accessing the model configuration
|
| 111 |
+
>>> configuration = model.config
|
| 112 |
+
```"""
|
| 113 |
+
|
| 114 |
+
model_type = "deepseek_v3"
|
| 115 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 116 |
+
|
| 117 |
+
def __init__(
|
| 118 |
+
self,
|
| 119 |
+
vocab_size=129280,
|
| 120 |
+
hidden_size=7168,
|
| 121 |
+
intermediate_size=18432,
|
| 122 |
+
moe_intermediate_size = 2048,
|
| 123 |
+
num_hidden_layers=61,
|
| 124 |
+
num_nextn_predict_layers=1,
|
| 125 |
+
num_attention_heads=128,
|
| 126 |
+
num_key_value_heads=128,
|
| 127 |
+
n_shared_experts = 1,
|
| 128 |
+
n_routed_experts = 256,
|
| 129 |
+
ep_size = 1,
|
| 130 |
+
routed_scaling_factor = 2.5,
|
| 131 |
+
kv_lora_rank = 512,
|
| 132 |
+
q_lora_rank = None,
|
| 133 |
+
qk_rope_head_dim = 64,
|
| 134 |
+
qk_layernorm = True,
|
| 135 |
+
v_head_dim = 128,
|
| 136 |
+
qk_nope_head_dim = 128,
|
| 137 |
+
qk_head_dim = None,
|
| 138 |
+
rope_interleave = True,
|
| 139 |
+
topk_method = 'noaux_tc',
|
| 140 |
+
n_group = 8,
|
| 141 |
+
topk_group = 4,
|
| 142 |
+
num_experts_per_tok = 8,
|
| 143 |
+
moe_layer_freq = 1,
|
| 144 |
+
first_k_dense_replace = 3,
|
| 145 |
+
gated_attention = True,
|
| 146 |
+
norm_topk_prob = True,
|
| 147 |
+
scoring_func = 'sigmoid',
|
| 148 |
+
aux_loss_alpha = 0.001,
|
| 149 |
+
seq_aux = True,
|
| 150 |
+
hidden_act="silu",
|
| 151 |
+
max_position_embeddings=4096,
|
| 152 |
+
initializer_range=0.02,
|
| 153 |
+
rms_norm_eps=1e-6,
|
| 154 |
+
use_cache=True,
|
| 155 |
+
pad_token_id=None,
|
| 156 |
+
bos_token_id=0,
|
| 157 |
+
eos_token_id=1,
|
| 158 |
+
pretraining_tp=1,
|
| 159 |
+
tie_word_embeddings=False,
|
| 160 |
+
rope_theta=10000.0,
|
| 161 |
+
rope_scaling=None,
|
| 162 |
+
attention_bias=False,
|
| 163 |
+
attention_dropout=0.0,
|
| 164 |
+
farskip=False,
|
| 165 |
+
tp_split=None,
|
| 166 |
+
farskip_start_idx=0,
|
| 167 |
+
farskip_end_idx=1e4,
|
| 168 |
+
apply_all_reduce=False,
|
| 169 |
+
attn_only_farskip=False,
|
| 170 |
+
mlp_only_farskip=False,
|
| 171 |
+
verbose=False,
|
| 172 |
+
**kwargs,
|
| 173 |
+
):
|
| 174 |
+
self.vocab_size = vocab_size
|
| 175 |
+
self.max_position_embeddings = max_position_embeddings
|
| 176 |
+
self.hidden_size = hidden_size
|
| 177 |
+
self.intermediate_size = intermediate_size
|
| 178 |
+
self.moe_intermediate_size = moe_intermediate_size
|
| 179 |
+
self.num_hidden_layers = num_hidden_layers
|
| 180 |
+
self.num_nextn_predict_layers = num_nextn_predict_layers
|
| 181 |
+
self.num_attention_heads = num_attention_heads
|
| 182 |
+
self.n_shared_experts = n_shared_experts
|
| 183 |
+
self.n_routed_experts = n_routed_experts
|
| 184 |
+
self.ep_size = ep_size
|
| 185 |
+
self.routed_scaling_factor = routed_scaling_factor
|
| 186 |
+
self.kv_lora_rank = kv_lora_rank
|
| 187 |
+
self.q_lora_rank = q_lora_rank
|
| 188 |
+
self.qk_layernorm = qk_layernorm
|
| 189 |
+
self.qk_rope_head_dim = qk_rope_head_dim
|
| 190 |
+
self.v_head_dim = v_head_dim
|
| 191 |
+
self.qk_nope_head_dim = qk_nope_head_dim
|
| 192 |
+
self.qk_head_dim = qk_head_dim if qk_head_dim is not None else qk_nope_head_dim + qk_rope_head_dim
|
| 193 |
+
self.rope_interleave = rope_interleave
|
| 194 |
+
# yarn rope init reads config.head_dim (falls back to hidden_size//num_heads
|
| 195 |
+
# otherwise). MLA rope operates on qk_rope_head_dim, so pin it here to match.
|
| 196 |
+
self.head_dim = qk_rope_head_dim
|
| 197 |
+
self.topk_method = topk_method
|
| 198 |
+
self.n_group = n_group
|
| 199 |
+
self.topk_group = topk_group
|
| 200 |
+
self.num_experts_per_tok = num_experts_per_tok
|
| 201 |
+
self.moe_layer_freq = moe_layer_freq
|
| 202 |
+
self.first_k_dense_replace = first_k_dense_replace
|
| 203 |
+
self.norm_topk_prob = norm_topk_prob
|
| 204 |
+
self.scoring_func = scoring_func
|
| 205 |
+
self.aux_loss_alpha = aux_loss_alpha
|
| 206 |
+
self.seq_aux = seq_aux
|
| 207 |
+
# for backward compatibility
|
| 208 |
+
if num_key_value_heads is None:
|
| 209 |
+
num_key_value_heads = num_attention_heads
|
| 210 |
+
|
| 211 |
+
self.num_key_value_heads = num_key_value_heads
|
| 212 |
+
self.hidden_act = hidden_act
|
| 213 |
+
self.initializer_range = initializer_range
|
| 214 |
+
self.rms_norm_eps = rms_norm_eps
|
| 215 |
+
self.pretraining_tp = pretraining_tp
|
| 216 |
+
self.use_cache = use_cache
|
| 217 |
+
self.rope_theta = rope_theta
|
| 218 |
+
self.rope_scaling = rope_scaling
|
| 219 |
+
self.attention_bias = attention_bias
|
| 220 |
+
self.attention_dropout = attention_dropout
|
| 221 |
+
self.farskip = farskip
|
| 222 |
+
self.tp_split = tp_split
|
| 223 |
+
self.farskip_start_idx = farskip_start_idx
|
| 224 |
+
self.farskip_end_idx = farskip_end_idx
|
| 225 |
+
self.apply_all_reduce = apply_all_reduce
|
| 226 |
+
self.attn_only_farskip = attn_only_farskip
|
| 227 |
+
self.mlp_only_farskip = mlp_only_farskip
|
| 228 |
+
self.verbose = verbose
|
| 229 |
+
self.gated_attention = gated_attention
|
| 230 |
+
|
| 231 |
+
super().__init__(
|
| 232 |
+
pad_token_id=pad_token_id,
|
| 233 |
+
bos_token_id=bos_token_id,
|
| 234 |
+
eos_token_id=eos_token_id,
|
| 235 |
+
tie_word_embeddings=tie_word_embeddings,
|
| 236 |
+
**kwargs,
|
| 237 |
+
)
|
generation_config.json
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_from_model_config": true,
|
| 3 |
+
"bos_token_id": 1,
|
| 4 |
+
"eos_token_id": 2,
|
| 5 |
+
"do_sample": true,
|
| 6 |
+
"temperature": 0.3,
|
| 7 |
+
"top_p": 0.95,
|
| 8 |
+
"transformers_version": "4.39.3"
|
| 9 |
+
}
|
images/fig_cost_performance.png
ADDED
|
Git LFS Details
|
images/result_table_base_long.png
ADDED
|
Git LFS Details
|
images/result_table_base_standard.png
ADDED
|
Git LFS Details
|
images/result_table_instruct.png
ADDED
|
Git LFS Details
|
merge_metadata.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"checkpoints": [
|
| 3 |
+
"/wekafs/prakmish/pretain_checkpoints_long_hf/exp_instella_16b_gated_farskip_overlap_midtraining_dolmino_100B_2e-4_iter_0021000-hf-with-mtp",
|
| 4 |
+
"/wekafs/prakmish/pretain_checkpoints_long_hf/exp_instella_16b_gated_farskip_overlap_midtraining_dolmino_100B_v1_2e-4_iter_0021000-hf-with-mtp",
|
| 5 |
+
"/wekafs/prakmish/pretain_checkpoints_long_hf/exp_instella_16b_gated_farskip_overlap_midtraining_dolmino_100B_v2_2e-4_iter_0022125-hf-with-mtp"
|
| 6 |
+
],
|
| 7 |
+
"weights_before_normalization": [
|
| 8 |
+
0.5,
|
| 9 |
+
0.5,
|
| 10 |
+
0.5
|
| 11 |
+
],
|
| 12 |
+
"normalized_weights": [
|
| 13 |
+
0.3333333333333333,
|
| 14 |
+
0.3333333333333333,
|
| 15 |
+
0.3333333333333333
|
| 16 |
+
],
|
| 17 |
+
"merge_dtype": "float32",
|
| 18 |
+
"total_tensors": 5568
|
| 19 |
+
}
|
model-00000-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:59a5edd7fa807e7a283d012b8993a7fa579da73eafe6921fe5355625d2c983c6
|
| 3 |
+
size 5363712448
|
model-00001-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d37cbdb2b78f13734ed9752678b5921da7a27f66c156caf989f369ec610824cc
|
| 3 |
+
size 5361485016
|
model-00002-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:82baf52fa5264d854b5a00e36212b259eac260ee3deb36b232185a4f7096b31d
|
| 3 |
+
size 5365546904
|
model-00003-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6fe8c67cb1c8777f7b2c30b4e6a317379faf0ac20ece411f82a8d3f77adaf942
|
| 3 |
+
size 5364822728
|
model-00004-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ba59a6c6093073fd640c05aafc9712f5d641acba9c982abb185483a430d879e2
|
| 3 |
+
size 5363582056
|
model-00005-of-00006.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:024dad22bb70e39a5b780490d0a8378be75519b14ee257b25e3750fd24f727a1
|
| 3 |
+
size 4907096096
|
model.safetensors.index.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
modeling_instella_moe.py
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Modular Instella-MoE for transformers 4.57.1.
|
| 3 |
+
|
| 4 |
+
This file imports the numerically-unchanged building blocks from the installed
|
| 5 |
+
`transformers.models.deepseek_v3` package and defines ONLY the classes that carry
|
| 6 |
+
a FarSkip or gated-attention delta:
|
| 7 |
+
|
| 8 |
+
* InstellaMoEForCausalLM
|
| 9 |
+
* InstellaMoEPreTrainedModel
|
| 10 |
+
* InstellaMoEModel - unwraps the residual tuple before the final norm
|
| 11 |
+
* FarSkipDecoderLayer - tuple-residual (residual, residual_no_routed) dataflow
|
| 12 |
+
* FarSkipMoE - returns (routed, shared) separately (FarSkip needs both)
|
| 13 |
+
* MLAGatedAttention - adds sigmoid `gate_proj` before `o_proj`
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
from typing import Optional, Union
|
| 17 |
+
|
| 18 |
+
import torch
|
| 19 |
+
from torch import nn
|
| 20 |
+
|
| 21 |
+
from transformers.cache_utils import Cache, DynamicCache
|
| 22 |
+
from transformers.generation import GenerationMixin
|
| 23 |
+
from transformers.masking_utils import create_causal_mask
|
| 24 |
+
from transformers.modeling_layers import GradientCheckpointingLayer
|
| 25 |
+
from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast
|
| 26 |
+
from transformers.modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 27 |
+
from transformers.processing_utils import Unpack
|
| 28 |
+
from transformers.utils import TransformersKwargs, auto_docstring, can_return_tuple
|
| 29 |
+
from transformers.utils.generic import check_model_inputs
|
| 30 |
+
|
| 31 |
+
from transformers.models.deepseek_v3.modeling_deepseek_v3 import (
|
| 32 |
+
DeepseekV3RMSNorm,
|
| 33 |
+
DeepseekV3RotaryEmbedding,
|
| 34 |
+
DeepseekV3MLP,
|
| 35 |
+
DeepseekV3MoE,
|
| 36 |
+
DeepseekV3TopkRouter,
|
| 37 |
+
DeepseekV3Attention,
|
| 38 |
+
apply_rotary_pos_emb,
|
| 39 |
+
apply_rotary_pos_emb_interleave,
|
| 40 |
+
eager_attention_forward,
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
from .configuration_instella_moe import InstellaMoEConfig
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class MLAGatedAttention(DeepseekV3Attention):
|
| 47 |
+
"""DeepSeek-V3 MLA with optional gated attention (attn_output * sigmoid(gate_proj(x)))."""
|
| 48 |
+
|
| 49 |
+
def __init__(self, config: InstellaMoEConfig, layer_idx: int):
|
| 50 |
+
super().__init__(config, layer_idx)
|
| 51 |
+
self.gated_attention = getattr(config, "gated_attention", False)
|
| 52 |
+
if self.gated_attention:
|
| 53 |
+
self.gate_proj = nn.Linear(
|
| 54 |
+
config.hidden_size, self.num_heads * self.v_head_dim, bias=False
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
def forward(
|
| 58 |
+
self,
|
| 59 |
+
hidden_states: torch.Tensor,
|
| 60 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 61 |
+
attention_mask: Optional[torch.Tensor],
|
| 62 |
+
past_key_values: Optional[Cache] = None,
|
| 63 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 64 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 65 |
+
) -> tuple[torch.Tensor, Optional[torch.Tensor]]:
|
| 66 |
+
batch_size, seq_length = hidden_states.shape[:-1]
|
| 67 |
+
query_shape = (batch_size, seq_length, -1, self.qk_head_dim)
|
| 68 |
+
key_shape = (batch_size, seq_length, -1, self.qk_nope_head_dim + self.v_head_dim)
|
| 69 |
+
|
| 70 |
+
if self.q_lora_rank is None:
|
| 71 |
+
q_states = self.q_proj(hidden_states)
|
| 72 |
+
else:
|
| 73 |
+
q_states = self.q_b_proj(self.q_a_layernorm(self.q_a_proj(hidden_states)))
|
| 74 |
+
q_states = q_states.view(query_shape).transpose(1, 2)
|
| 75 |
+
q_pass, q_rot = torch.split(q_states, [self.qk_nope_head_dim, self.qk_rope_head_dim], dim=-1)
|
| 76 |
+
|
| 77 |
+
compressed_kv = self.kv_a_proj_with_mqa(hidden_states)
|
| 78 |
+
k_pass, k_rot = torch.split(compressed_kv, [self.kv_lora_rank, self.qk_rope_head_dim], dim=-1)
|
| 79 |
+
|
| 80 |
+
k_pass = self.kv_b_proj(self.kv_a_layernorm(k_pass)).view(key_shape).transpose(1, 2)
|
| 81 |
+
k_pass, value_states = torch.split(k_pass, [self.qk_nope_head_dim, self.v_head_dim], dim=-1)
|
| 82 |
+
|
| 83 |
+
k_rot = k_rot.view(batch_size, 1, seq_length, self.qk_rope_head_dim)
|
| 84 |
+
|
| 85 |
+
cos, sin = position_embeddings
|
| 86 |
+
if self.config.rope_interleave:
|
| 87 |
+
q_rot, k_rot = apply_rotary_pos_emb_interleave(q_rot, k_rot, cos, sin)
|
| 88 |
+
else:
|
| 89 |
+
q_rot, k_rot = apply_rotary_pos_emb(q_rot, k_rot, cos, sin)
|
| 90 |
+
k_rot = k_rot.expand(*k_pass.shape[:-1], -1)
|
| 91 |
+
|
| 92 |
+
query_states = torch.cat((q_pass, q_rot), dim=-1)
|
| 93 |
+
key_states = torch.cat((k_pass, k_rot), dim=-1)
|
| 94 |
+
|
| 95 |
+
if past_key_values is not None:
|
| 96 |
+
cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}
|
| 97 |
+
key_states, value_states = past_key_values.update(
|
| 98 |
+
key_states, value_states, self.layer_idx, cache_kwargs
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
if self.config._attn_implementation == "flash_attention_2" and self.qk_head_dim != self.v_head_dim:
|
| 102 |
+
value_states = nn.functional.pad(value_states, [0, self.qk_head_dim - self.v_head_dim])
|
| 103 |
+
|
| 104 |
+
attention_interface = eager_attention_forward
|
| 105 |
+
if self.config._attn_implementation != "eager":
|
| 106 |
+
attention_interface = ALL_ATTENTION_FUNCTIONS[self.config._attn_implementation]
|
| 107 |
+
|
| 108 |
+
attn_output, attn_weights = attention_interface(
|
| 109 |
+
self,
|
| 110 |
+
query_states,
|
| 111 |
+
key_states,
|
| 112 |
+
value_states,
|
| 113 |
+
attention_mask,
|
| 114 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 115 |
+
scaling=self.scaling,
|
| 116 |
+
**kwargs,
|
| 117 |
+
)
|
| 118 |
+
|
| 119 |
+
if self.config._attn_implementation == "flash_attention_2" and self.qk_head_dim != self.v_head_dim:
|
| 120 |
+
attn_output = attn_output[:, :, :, : self.v_head_dim]
|
| 121 |
+
|
| 122 |
+
attn_output = attn_output.reshape(batch_size, seq_length, -1).contiguous()
|
| 123 |
+
|
| 124 |
+
if self.gated_attention:
|
| 125 |
+
attn_output = attn_output * torch.sigmoid(self.gate_proj(hidden_states))
|
| 126 |
+
|
| 127 |
+
attn_output = self.o_proj(attn_output)
|
| 128 |
+
return attn_output, attn_weights
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
class FarSkipMoE(DeepseekV3MoE):
|
| 132 |
+
"""FarSkip-Collective MoE that returns routed and shared outputs separately so FarSkip can route them
|
| 133 |
+
into the two residual streams independently."""
|
| 134 |
+
|
| 135 |
+
def forward(self, hidden_states):
|
| 136 |
+
residuals = hidden_states
|
| 137 |
+
orig_shape = hidden_states.shape
|
| 138 |
+
topk_indices, topk_weights = self.gate(hidden_states)
|
| 139 |
+
hidden_states = hidden_states.view(-1, hidden_states.shape[-1])
|
| 140 |
+
routed = self.moe(hidden_states, topk_indices, topk_weights).view(*orig_shape)
|
| 141 |
+
shared = self.shared_experts(residuals)
|
| 142 |
+
# First element is the full MoE output (routed + shared) so the main residual
|
| 143 |
+
# stream stays numerically identical to stock DeepSeek-V3; `shared` is returned
|
| 144 |
+
# separately so FarSkip can build the routed-free residual stream.
|
| 145 |
+
return routed + shared, shared
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
class FarSkipDecoderLayer(GradientCheckpointingLayer):
|
| 149 |
+
"""
|
| 150 |
+
FarSkip-Collective connectivity decoder layer
|
| 151 |
+
"""
|
| 152 |
+
def __init__(self, config: InstellaMoEConfig, layer_idx: int):
|
| 153 |
+
super().__init__()
|
| 154 |
+
self.hidden_size = config.hidden_size
|
| 155 |
+
self.self_attn = MLAGatedAttention(config=config, layer_idx=layer_idx)
|
| 156 |
+
|
| 157 |
+
if layer_idx >= config.first_k_dense_replace:
|
| 158 |
+
self.mlp = FarSkipMoE(config)
|
| 159 |
+
else:
|
| 160 |
+
self.mlp = DeepseekV3MLP(config)
|
| 161 |
+
|
| 162 |
+
self.input_layernorm = DeepseekV3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 163 |
+
self.post_attention_layernorm = DeepseekV3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 164 |
+
|
| 165 |
+
self.config = config
|
| 166 |
+
self.layer_idx = layer_idx
|
| 167 |
+
self.farskip = (
|
| 168 |
+
config.farskip
|
| 169 |
+
and layer_idx >= config.farskip_start_idx
|
| 170 |
+
and layer_idx <= min(config.farskip_end_idx, config.num_hidden_layers - 1)
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
def forward(
|
| 174 |
+
self,
|
| 175 |
+
hidden_states,
|
| 176 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 177 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 178 |
+
past_key_values: Optional[Cache] = None,
|
| 179 |
+
use_cache: Optional[bool] = False,
|
| 180 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 181 |
+
position_embeddings: Optional[tuple[torch.Tensor, torch.Tensor]] = None,
|
| 182 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 183 |
+
):
|
| 184 |
+
if self.farskip:
|
| 185 |
+
if not isinstance(hidden_states, tuple): # first farskip layer
|
| 186 |
+
residual = hidden_states
|
| 187 |
+
input_to_attn = hidden_states
|
| 188 |
+
input_to_mlp = hidden_states
|
| 189 |
+
else:
|
| 190 |
+
residual = hidden_states[0]
|
| 191 |
+
input_to_attn = hidden_states[1]
|
| 192 |
+
input_to_mlp = residual
|
| 193 |
+
if self.config.attn_only_farskip:
|
| 194 |
+
input_to_mlp = None
|
| 195 |
+
if self.config.mlp_only_farskip:
|
| 196 |
+
input_to_attn = residual
|
| 197 |
+
else:
|
| 198 |
+
if isinstance(hidden_states, tuple):
|
| 199 |
+
hidden_states = hidden_states[0]
|
| 200 |
+
residual = hidden_states
|
| 201 |
+
input_to_attn = hidden_states
|
| 202 |
+
input_to_mlp = None
|
| 203 |
+
|
| 204 |
+
input_to_attn = self.input_layernorm(input_to_attn)
|
| 205 |
+
|
| 206 |
+
attn_output, _ = self.self_attn(
|
| 207 |
+
hidden_states=input_to_attn,
|
| 208 |
+
position_embeddings=position_embeddings,
|
| 209 |
+
attention_mask=attention_mask,
|
| 210 |
+
past_key_values=past_key_values,
|
| 211 |
+
cache_position=cache_position,
|
| 212 |
+
**kwargs,
|
| 213 |
+
)
|
| 214 |
+
residual = residual + attn_output
|
| 215 |
+
|
| 216 |
+
if input_to_mlp is None:
|
| 217 |
+
input_to_mlp = residual
|
| 218 |
+
input_to_mlp = self.post_attention_layernorm(input_to_mlp)
|
| 219 |
+
|
| 220 |
+
if isinstance(self.mlp, FarSkipMoE):
|
| 221 |
+
mlp_output, mlp_shared_output = self.mlp(input_to_mlp)
|
| 222 |
+
residual_no_routed = residual + mlp_shared_output
|
| 223 |
+
residual = residual + mlp_output
|
| 224 |
+
# residual_no_routed is combine-free and feeds the next block's attention
|
| 225 |
+
hidden_states = (residual, residual_no_routed)
|
| 226 |
+
else:
|
| 227 |
+
hidden_states = residual + self.mlp(input_to_mlp)
|
| 228 |
+
|
| 229 |
+
return hidden_states
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
@auto_docstring
|
| 233 |
+
class InstellaMoEPreTrainedModel(PreTrainedModel):
|
| 234 |
+
config: InstellaMoEConfig
|
| 235 |
+
config_class = InstellaMoEConfig
|
| 236 |
+
base_model_prefix = "model"
|
| 237 |
+
supports_gradient_checkpointing = True
|
| 238 |
+
_no_split_modules = ["FarSkipDecoderLayer"]
|
| 239 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 240 |
+
_supports_flash_attn = True
|
| 241 |
+
_supports_sdpa = True
|
| 242 |
+
_supports_flex_attn = True
|
| 243 |
+
_can_compile_fullgraph = False
|
| 244 |
+
_supports_attention_backend = True
|
| 245 |
+
_can_record_outputs = {
|
| 246 |
+
"hidden_states": FarSkipDecoderLayer,
|
| 247 |
+
"attentions": MLAGatedAttention,
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
def _init_weights(self, module):
|
| 251 |
+
super()._init_weights(module)
|
| 252 |
+
if isinstance(module, DeepseekV3TopkRouter):
|
| 253 |
+
module.weight.data.normal_(mean=0.0, std=self.config.initializer_range)
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
@auto_docstring
|
| 257 |
+
class InstellaMoEModel(InstellaMoEPreTrainedModel):
|
| 258 |
+
def __init__(self, config: InstellaMoEConfig):
|
| 259 |
+
super().__init__(config)
|
| 260 |
+
self.padding_idx = config.pad_token_id
|
| 261 |
+
self.vocab_size = config.vocab_size
|
| 262 |
+
|
| 263 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 264 |
+
self.layers = nn.ModuleList(
|
| 265 |
+
[FarSkipDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 266 |
+
)
|
| 267 |
+
self.norm = DeepseekV3RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 268 |
+
self.rotary_emb = DeepseekV3RotaryEmbedding(config=config)
|
| 269 |
+
self.gradient_checkpointing = False
|
| 270 |
+
|
| 271 |
+
self.post_init()
|
| 272 |
+
|
| 273 |
+
@check_model_inputs
|
| 274 |
+
@auto_docstring
|
| 275 |
+
def forward(
|
| 276 |
+
self,
|
| 277 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 278 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 279 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 280 |
+
past_key_values: Optional[Cache] = None,
|
| 281 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 282 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 283 |
+
use_cache: Optional[bool] = None,
|
| 284 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 285 |
+
) -> BaseModelOutputWithPast:
|
| 286 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 287 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 288 |
+
|
| 289 |
+
if inputs_embeds is None:
|
| 290 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 291 |
+
|
| 292 |
+
if use_cache and past_key_values is None:
|
| 293 |
+
past_key_values = DynamicCache(config=self.config)
|
| 294 |
+
|
| 295 |
+
if cache_position is None:
|
| 296 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 297 |
+
cache_position = torch.arange(
|
| 298 |
+
past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
|
| 299 |
+
)
|
| 300 |
+
|
| 301 |
+
if position_ids is None:
|
| 302 |
+
position_ids = cache_position.unsqueeze(0)
|
| 303 |
+
|
| 304 |
+
causal_mask = create_causal_mask(
|
| 305 |
+
config=self.config,
|
| 306 |
+
input_embeds=inputs_embeds,
|
| 307 |
+
attention_mask=attention_mask,
|
| 308 |
+
cache_position=cache_position,
|
| 309 |
+
past_key_values=past_key_values,
|
| 310 |
+
position_ids=position_ids,
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
hidden_states = inputs_embeds
|
| 314 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 315 |
+
|
| 316 |
+
for decoder_layer in self.layers[: self.config.num_hidden_layers]:
|
| 317 |
+
hidden_states = decoder_layer(
|
| 318 |
+
hidden_states,
|
| 319 |
+
attention_mask=causal_mask,
|
| 320 |
+
position_ids=position_ids,
|
| 321 |
+
past_key_values=past_key_values,
|
| 322 |
+
cache_position=cache_position,
|
| 323 |
+
position_embeddings=position_embeddings,
|
| 324 |
+
**kwargs,
|
| 325 |
+
)
|
| 326 |
+
|
| 327 |
+
if isinstance(hidden_states, tuple):
|
| 328 |
+
hidden_states = hidden_states[0] # routed-inclusive residual stream
|
| 329 |
+
hidden_states = self.norm(hidden_states)
|
| 330 |
+
return BaseModelOutputWithPast(
|
| 331 |
+
last_hidden_state=hidden_states,
|
| 332 |
+
past_key_values=past_key_values,
|
| 333 |
+
)
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
@auto_docstring
|
| 337 |
+
class InstellaMoEForCausalLM(InstellaMoEPreTrainedModel, GenerationMixin):
|
| 338 |
+
_tied_weights_keys = ["lm_head.weight"]
|
| 339 |
+
_tp_plan = {"lm_head": "colwise_rep"}
|
| 340 |
+
_pp_plan = {"lm_head": (["hidden_states"], ["logits"])}
|
| 341 |
+
|
| 342 |
+
def __init__(self, config):
|
| 343 |
+
super().__init__(config)
|
| 344 |
+
self.model = InstellaMoEModel(config)
|
| 345 |
+
self.vocab_size = config.vocab_size
|
| 346 |
+
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 347 |
+
|
| 348 |
+
self.post_init()
|
| 349 |
+
|
| 350 |
+
@can_return_tuple
|
| 351 |
+
@auto_docstring
|
| 352 |
+
def forward(
|
| 353 |
+
self,
|
| 354 |
+
input_ids: Optional[torch.LongTensor] = None,
|
| 355 |
+
attention_mask: Optional[torch.Tensor] = None,
|
| 356 |
+
position_ids: Optional[torch.LongTensor] = None,
|
| 357 |
+
past_key_values: Optional[Cache] = None,
|
| 358 |
+
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 359 |
+
labels: Optional[torch.LongTensor] = None,
|
| 360 |
+
use_cache: Optional[bool] = None,
|
| 361 |
+
cache_position: Optional[torch.LongTensor] = None,
|
| 362 |
+
logits_to_keep: Union[int, torch.Tensor] = 0,
|
| 363 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 364 |
+
) -> CausalLMOutputWithPast:
|
| 365 |
+
outputs: BaseModelOutputWithPast = self.model(
|
| 366 |
+
input_ids=input_ids,
|
| 367 |
+
attention_mask=attention_mask,
|
| 368 |
+
position_ids=position_ids,
|
| 369 |
+
past_key_values=past_key_values,
|
| 370 |
+
inputs_embeds=inputs_embeds,
|
| 371 |
+
use_cache=use_cache,
|
| 372 |
+
cache_position=cache_position,
|
| 373 |
+
**kwargs,
|
| 374 |
+
)
|
| 375 |
+
|
| 376 |
+
hidden_states = outputs.last_hidden_state
|
| 377 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 378 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 379 |
+
|
| 380 |
+
loss = None
|
| 381 |
+
if labels is not None:
|
| 382 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.vocab_size, **kwargs)
|
| 383 |
+
|
| 384 |
+
return CausalLMOutputWithPast(
|
| 385 |
+
loss=loss,
|
| 386 |
+
logits=logits,
|
| 387 |
+
past_key_values=outputs.past_key_values,
|
| 388 |
+
hidden_states=outputs.hidden_states,
|
| 389 |
+
attentions=outputs.attentions,
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
__all__ = [
|
| 394 |
+
"InstellaMoEPreTrainedModel",
|
| 395 |
+
"InstellaMoEModel",
|
| 396 |
+
"InstellaMoEForCausalLM",
|
| 397 |
+
]
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": {
|
| 3 |
+
"content": "<|begin▁of▁sentence|>",
|
| 4 |
+
"lstrip": false,
|
| 5 |
+
"normalized": false,
|
| 6 |
+
"rstrip": false,
|
| 7 |
+
"single_word": false
|
| 8 |
+
},
|
| 9 |
+
"eos_token": {
|
| 10 |
+
"content": "<|end▁of▁sentence|>",
|
| 11 |
+
"lstrip": false,
|
| 12 |
+
"normalized": false,
|
| 13 |
+
"rstrip": false,
|
| 14 |
+
"single_word": false
|
| 15 |
+
},
|
| 16 |
+
"pad_token": {
|
| 17 |
+
"content": "<|end▁of▁sentence|>",
|
| 18 |
+
"lstrip": false,
|
| 19 |
+
"normalized": false,
|
| 20 |
+
"rstrip": false,
|
| 21 |
+
"single_word": false
|
| 22 |
+
}
|
| 23 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_bos_token": true,
|
| 3 |
+
"add_eos_token": false,
|
| 4 |
+
"bos_token": {
|
| 5 |
+
"__type": "AddedToken",
|
| 6 |
+
"content": "<|begin▁of▁sentence|>",
|
| 7 |
+
"lstrip": false,
|
| 8 |
+
"normalized": true,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"clean_up_tokenization_spaces": false,
|
| 13 |
+
"eos_token": {
|
| 14 |
+
"__type": "AddedToken",
|
| 15 |
+
"content": "<|end▁of▁sentence|>",
|
| 16 |
+
"lstrip": false,
|
| 17 |
+
"normalized": true,
|
| 18 |
+
"rstrip": false,
|
| 19 |
+
"single_word": false
|
| 20 |
+
},
|
| 21 |
+
"legacy": true,
|
| 22 |
+
"model_max_length": 131072,
|
| 23 |
+
"pad_token": {
|
| 24 |
+
"__type": "AddedToken",
|
| 25 |
+
"content": "<|end▁of▁sentence|>",
|
| 26 |
+
"lstrip": false,
|
| 27 |
+
"normalized": true,
|
| 28 |
+
"rstrip": false,
|
| 29 |
+
"single_word": false
|
| 30 |
+
},
|
| 31 |
+
"sp_model_kwargs": {},
|
| 32 |
+
"unk_token": null,
|
| 33 |
+
"tokenizer_class": "LlamaTokenizerFast",
|
| 34 |
+
"chat_template": "{% if not add_generation_prompt is defined %}{% set add_generation_prompt = false %}{% endif %}{% set ns = namespace(is_first=false, is_tool=false, is_output_first=true, system_prompt='', is_first_sp=true) %}{%- for message in messages %}{%- if message['role'] == 'system' %}{%- if ns.is_first_sp %}{% set ns.system_prompt = ns.system_prompt + message['content'] %}{% set ns.is_first_sp = false %}{%- else %}{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}{%- endif %}{%- endif %}{%- endfor %}{{bos_token}}{{ns.system_prompt}}{%- for message in messages %}{%- if message['role'] == 'user' %}{%- set ns.is_tool = false -%}{{'<|User|>' + message['content']}}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is none %}{%- set ns.is_tool = false -%}{%- for tool in message['tool_calls']%}{%- if not ns.is_first %}{{'<|Assistant|><|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}{%- set ns.is_first = true -%}{%- else %}{{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments'] + '\n' + '```' + '<|tool▁call▁end|>'}}{{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}{%- endif %}{%- endfor %}{%- endif %}{%- if message['role'] == 'assistant' and message['content'] is not none %}{%- if ns.is_tool %}{{'<|tool▁outputs▁end|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- set ns.is_tool = false -%}{%- else %}{{'<|Assistant|>' + message['content'] + '<|end▁of▁sentence|>'}}{%- endif %}{%- endif %}{%- if message['role'] == 'tool' %}{%- set ns.is_tool = true -%}{%- if ns.is_output_first %}{{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- set ns.is_output_first = false %}{%- else %}{{'\n<|tool▁output▁begin|>' + message['content'] + '<|tool▁output▁end|>'}}{%- endif %}{%- endif %}{%- endfor -%}{% if ns.is_tool %}{{'<|tool▁outputs▁end|>'}}{% endif %}{% if add_generation_prompt and not ns.is_tool %}{{'<|Assistant|>'}}{% endif %}"
|
| 35 |
+
}
|