Skip to content
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@
title: OlmoHybrid
- local: model_doc/openai_privacy_filter
title: OpenAI Privacy Filter
- local: model_doc/openpangu_v2
title: OpenPanguV2
- local: model_doc/opt
title: OPT
- local: model_doc/pegasus
Expand Down
84 changes: 84 additions & 0 deletions docs/source/en/model_doc/openpangu_v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<!--Copyright (c) 2026 Huawei Technologies Co., Ltd. All Rights Reserved.
Copyright 2026 The HuggingFace Inc. team. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.

⚠️ 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-07-06.*

# OpenPanguV2

OpenPanguV2 is an MoE model trained on Ascend. Its context length is 512k. During Post-training, OpenPanguV2 is
trained through unified SFT with slow and fast thinking capability, multiple specialist RL traning, on-policy
distillation combining multiple RL specialists.

## Architecture

OpenPanguV2 brings several major architectural improvements:

* **Efficient attention**: The model retains MLA for efficient inference and combines DSA and SWA in a 1:2 layer ratio.
SWA layers handle local-window modeling, while DSA layers capture sparse global context. This design lowers compute,
memory footprint, and memory access costs for long-context inference while preserving accuracy.
* **Residual topology**: TThe conventional residual path is replaced with a 4-stream mHC design, improving representation
diversity and generalization.
* **Optimizer**: Training uses the Muon optimizer for faster convergence.

## Usage examples

The example below demonstrates how to generate text with [`Pipeline`] or the [`AutoModelForCausalLM`] class.

```python
from transformers import pipeline


pipe = pipeline(
task="text-generation",
model="openpangu/openPangu-2.0-Flash",
device_map="auto"
)
pipe("Give me a short introduction to large language model.")
```

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "openpangu/openPangu-2.0-Flash"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
device_map="auto",
)
input_ids = tokenizer("Give me a short introduction to large language model.", return_tensors="pt").to(model.device)

output = model.generate(**input_ids, max_new_tokens=50)
print(tokenizer.decode(output[0], skip_special_tokens=True))
```

## OpenPanguV2Config

[[autodoc]] OpenPanguV2Config

## OpenPanguV2Tokenizer

[[autodoc]] OpenPanguV2Tokenizer

## OpenPanguV2Model

[[autodoc]] OpenPanguV2Model
- forward

## OpenPanguV2ForCausalLM

[[autodoc]] OpenPanguV2ForCausalLM
- forward
1 change: 1 addition & 0 deletions src/transformers/conversion_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"qwen3_5_moe_text": "qwen3_5_text",
"llava_next_video": "llava_next",
"llava_onevision": "llava_next",
"openpangu_v2": "qwen2_moe",
# class-based mappings
"PaliGemmaModel": "LlavaModel",
"AyaVisionModel": "LlavaModel",
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@
from .oneformer import *
from .openai import *
from .openai_privacy_filter import *
from .openpangu_v2 import *
from .opt import *
from .ovis2 import *
from .owlv2 import *
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/auto_mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@
("oneformer", "OneFormerConfig"),
("openai-gpt", "OpenAIGPTConfig"),
("openai_privacy_filter", "OpenAIPrivacyFilterConfig"),
("openpangu_v2", "OpenPanguV2Config"),
("opt", "OPTConfig"),
("ovis2", "Ovis2Config"),
("owlv2", "Owlv2Config"),
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("oneformer", "OneFormerModel"),
("openai-gpt", "OpenAIGPTModel"),
("openai_privacy_filter", "OpenAIPrivacyFilterModel"),
("openpangu_v2", "OpenPanguV2Model"),
("opt", "OPTModel"),
("ovis2", "Ovis2Model"),
("owlv2", "Owlv2Model"),
Expand Down Expand Up @@ -785,6 +786,7 @@ class _BaseModelWithGenerate(PreTrainedModel, GenerationMixin):
("olmo_hybrid", "OlmoHybridForCausalLM"),
("olmoe", "OlmoeForCausalLM"),
("openai-gpt", "OpenAIGPTLMHeadModel"),
("openpangu_v2", "OpenPanguV2ForCausalLM"),
("opt", "OPTForCausalLM"),
("pegasus", "PegasusForCausalLM"),
("persimmon", "PersimmonForCausalLM"),
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/auto/tokenization_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@
("omdet-turbo", "CLIPTokenizer" if is_tokenizers_available() else None),
("oneformer", "CLIPTokenizer" if is_tokenizers_available() else None),
("openai-gpt", "OpenAIGPTTokenizer" if is_tokenizers_available() else None),
("openpangu_v2", "OpenPanguV2Tokenizer" if is_tokenizers_available() else None),
("opt", "GPT2Tokenizer" if is_tokenizers_available() else None),
("ovis2", "Qwen2Tokenizer" if is_tokenizers_available() else None),
("owlv2", "CLIPTokenizer" if is_tokenizers_available() else None),
Expand Down
29 changes: 29 additions & 0 deletions src/transformers/models/openpangu_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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.

from typing import TYPE_CHECKING

from ...utils import _LazyModule
from ...utils.import_utils import define_import_structure


if TYPE_CHECKING:
from .configuration_openpangu_v2 import *
from .modeling_openpangu_v2 import *
from .tokenization_openpangu_v2 import *
else:
import sys

_file = globals()["__file__"]
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
Loading
Loading