Repository navigation
Add TeleChat #50477
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
Closed
+1,173
−0
Closed
Add TeleChat #50477
Changes from 12 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fbe29f9
Add InternLM3, IQuestCoder and TeleChat3
hmellor c76bc6d
Fill integration test expectations from B200 runs
hmellor b91d47e
Add TeleChat (v1, TeleChat2 and TeleChat2.5)
hmellor 0c3262b
Load InternLM3, IQuestCoder and TeleChat tokenizers without remote code
hmellor d01eabc
Fix SentencePiece decoding without byte fallback and test offsets aga…
hmellor 1c05d24
Move the SentencePiece conversion changes to #50555
hmellor a2281c2
Use the Llama implementation for InternLM3, IQuestCoder and TeleChat3
hmellor cb9084c
Drop the redundant checkpoint from TeleChatForCausalLM's auto_docstring
hmellor 88d04c3
Split TeleChat's fused key/value projection with the conversion mapping
hmellor 8e50530
Drop the modular files of the config-only models
hmellor 53a3868
Drop the integration tests of the config-only models
hmellor 344b8d7
Keep only the TeleChat3 config tests for the config-only models
hmellor f0f228b
Address review: restore config modular files, TeleChat-only KV op, ca…
hmellor 4b91134
Split InternLM3, IQuestCoder and TeleChat3 into their own PRs
hmellor df06e02
Run the tensor parallel tests on TeleChat
hmellor 011bfbd
Load TeleChat2-3B with the default dtype in the integration tests
hmellor 2dda807
Pop TeleChat's original RoPE keys up front
hmellor 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| <!--Copyright 2026 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 contains specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was contributed to Hugging Face Transformers on 2026-11-10.* | ||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # InternLM3 | ||
|
|
||
| [InternLM3](https://huggingface.co/internlm/internlm3-8b-instruct) is an 8B instruction-tuned language model developed by [Shanghai AI Laboratory](https://huggingface.co/internlm). Its architecture is the same as [Llama](./llama). Its config names the biases of the query, key and value projections `qkv_bias` and those of the attention output projection and MLP layers `bias`; [`InternLM3Config`] loads them as `attention_bias` and `mlp_bias`, and requires them to be equal, as they are in the released checkpoints. | ||
|
|
||
| The auto classes load it with the Llama implementation ([`LlamaModel`], [`LlamaForCausalLM`], [`LlamaForSequenceClassification`], [`LlamaForQuestionAnswering`] and [`LlamaForTokenClassification`]), so only [`InternLM3Config`] is specific to InternLM3. | ||
|
|
||
| The example below demonstrates how to generate text with the [`AutoModelForCausalLM`] class. | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained("internlm/internlm3-8b-instruct") | ||
| model = AutoModelForCausalLM.from_pretrained("internlm/internlm3-8b-instruct", device_map="auto") | ||
|
|
||
| messages = [{"role": "user", "content": "Explain the Pythagorean theorem in one sentence."}] | ||
| inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True) | ||
| output = model.generate(**inputs.to(model.device), max_new_tokens=64) | ||
| print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True)) | ||
| ``` | ||
|
|
||
| ## InternLM3Config | ||
|
|
||
| [[autodoc]] InternLM3Config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <!--Copyright 2026 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 contains specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was contributed to Hugging Face Transformers on 2026-11-10.* | ||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # IQuestCoder | ||
|
|
||
| [IQuest-Coder-V1](https://huggingface.co/IQuestLab/IQuest-Coder-V1-40B-Instruct) is a family of code language models developed by [IQuest Lab](https://huggingface.co/IQuestLab), available in 7B, 14B and 40B sizes with base, instruct and thinking variants. Its architecture is the same as [Llama](./llama). | ||
|
|
||
| The looped `IQuest-Coder-V1-*-Loop-*` checkpoints use a different architecture and aren't supported by this model. | ||
|
hmellor marked this conversation as resolved.
Resolved
|
||
|
|
||
| The tokenizer is built from the checkpoints' SentencePiece model. Many of its pieces share the same score, and SentencePiece breaks those ties by position, which the `tokenizers` library can't reproduce, so a small fraction of texts tokenize differently from the original remote code. | ||
|
hmellor marked this conversation as resolved.
Resolved
|
||
|
|
||
| The auto classes load it with the Llama implementation ([`LlamaModel`], [`LlamaForCausalLM`], [`LlamaForSequenceClassification`], [`LlamaForQuestionAnswering`] and [`LlamaForTokenClassification`]), so only [`IQuestCoderConfig`] is specific to IQuestCoder. | ||
|
|
||
| The example below demonstrates how to generate text with the [`AutoModelForCausalLM`] class. | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained("IQuestLab/IQuest-Coder-V1-7B-Instruct") | ||
| model = AutoModelForCausalLM.from_pretrained("IQuestLab/IQuest-Coder-V1-7B-Instruct", device_map="auto") | ||
|
|
||
| messages = [{"role": "user", "content": "Write a Python function that checks whether a number is prime."}] | ||
| inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True) | ||
| output = model.generate(**inputs.to(model.device), max_new_tokens=128) | ||
| print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True)) | ||
| ``` | ||
|
|
||
| ## IQuestCoderConfig | ||
|
|
||
| [[autodoc]] IQuestCoderConfig | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <!--Copyright 2026 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 contains specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was contributed to Hugging Face Transformers on 2026-11-10.* | ||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # TeleChat | ||
|
|
||
| [TeleChat](https://huggingface.co/Tele-AI) is a family of language models developed by [China Telecom Artificial Intelligence Technology](https://huggingface.co/Tele-AI), covering TeleChat (1B to 12B), TeleChat2 (3B to 115B) and TeleChat2.5 (35B and 115B). TeleChat3 is a separate model, see [TeleChat3](./telechat3). | ||
|
|
||
| Its architecture is the same as [Llama](./llama), except that: | ||
|
|
||
| - only the attention output projection and the down projection of the MLP have biases; | ||
| - once the sequence grows beyond `training_seqlen`, RoPE is rescaled with a stepwise NTK scaling of its base and the cos/sin are scaled by `0.1 * ln(seq_len / training_seqlen) + 1`. | ||
|
|
||
| The original checkpoints use different parameter names and fuse the key and value projections per head (`[k_0, v_0, k_1, v_1, ...]`). They are converted when the model is loaded, and `save_pretrained` writes the original layout back. | ||
|
hmellor marked this conversation as resolved.
Resolved
|
||
|
|
||
| TeleChat-52B uses a different architecture and isn't supported by this model. | ||
|
|
||
| The example below demonstrates how to generate text with the [`AutoModelForCausalLM`] class. | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained("Tele-AI/TeleChat2-3B") | ||
| model = AutoModelForCausalLM.from_pretrained("Tele-AI/TeleChat2-3B", device_map="auto") | ||
|
|
||
| messages = [{"role": "user", "content": "Explain the Pythagorean theorem in one sentence."}] | ||
| inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True) | ||
| output = model.generate(**inputs.to(model.device), max_new_tokens=64) | ||
| print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True)) | ||
| ``` | ||
|
|
||
| ## TeleChatConfig | ||
|
|
||
| [[autodoc]] TeleChatConfig | ||
|
|
||
| ## TeleChatModel | ||
|
|
||
| [[autodoc]] TeleChatModel | ||
| - forward | ||
|
|
||
| ## TeleChatForCausalLM | ||
|
|
||
| [[autodoc]] TeleChatForCausalLM | ||
| - forward | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <!--Copyright 2026 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 contains specific syntax for our doc-builder (similar to MDX) that may not be | ||
| rendered properly in your Markdown viewer. | ||
|
|
||
| --> | ||
| *This model was contributed to Hugging Face Transformers on 2026-11-10.* | ||
| <div style="float: right;"> | ||
| <div class="flex flex-wrap space-x-1"> | ||
| <img alt="FlashAttention" src="https://img.shields.io/badge/%E2%9A%A1%EF%B8%8E%20FlashAttention-eae0c8?style=flat"> | ||
| <img alt="SDPA" src="https://img.shields.io/badge/SDPA-DE3412?style=flat&logo=pytorch&logoColor=white"> | ||
| </div> | ||
| </div> | ||
|
|
||
| # TeleChat3 | ||
|
|
||
| [TeleChat3](https://huggingface.co/Tele-AI/TeleChat3-36B-Thinking) is a family of 36B reasoning language models developed by [China Telecom Artificial Intelligence Technology](https://huggingface.co/Tele-AI), including the general-purpose TeleChat3-36B-Thinking and the code-focused TeleChat3-Coder-36B-Thinking. Its architecture is the same as [Llama](./llama). | ||
|
|
||
| The original checkpoints use a custom `"telechat3-yarn"` RoPE type, which is YaRN with 0.07 instead of 0.1 as the coefficient of its default attention factor. [`TeleChat3Config`] converts it to `"yarn"` with an explicit `attention_factor` when the config is loaded. | ||
|
|
||
| The auto classes load it with the Llama implementation ([`LlamaModel`], [`LlamaForCausalLM`], [`LlamaForSequenceClassification`], [`LlamaForQuestionAnswering`] and [`LlamaForTokenClassification`]), so only [`TeleChat3Config`] is specific to TeleChat3. | ||
|
|
||
| The example below demonstrates how to generate text with the [`AutoModelForCausalLM`] class. | ||
|
|
||
| ```python | ||
| from transformers import AutoModelForCausalLM, AutoTokenizer | ||
|
|
||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained("Tele-AI/TeleChat3-36B-Thinking") | ||
| model = AutoModelForCausalLM.from_pretrained("Tele-AI/TeleChat3-36B-Thinking", device_map="auto") | ||
|
|
||
| messages = [{"role": "user", "content": "Explain the Pythagorean theorem in one sentence."}] | ||
| inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt", return_dict=True) | ||
| output = model.generate(**inputs.to(model.device), max_new_tokens=256) | ||
| print(tokenizer.decode(output[0][inputs["input_ids"].shape[1] :], skip_special_tokens=True)) | ||
| ``` | ||
|
|
||
| ## TeleChat3Config | ||
|
|
||
| [[autodoc]] TeleChat3Config |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.