Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f88c6a8
add support gigachat3
Mohamed-Ashraf273 Mar 3, 2026
c26ffe8
support gigacgat3
Mohamed-Ashraf273 Mar 3, 2026
751cd02
add tests & create tiny model
Mohamed-Ashraf273 Mar 3, 2026
0d16b4f
add tests and fix issues
Mohamed-Ashraf273 Mar 4, 2026
f2a1e53
fix version skip test
Mohamed-Ashraf273 Mar 4, 2026
aac19fb
add docs & modify patcher
Mohamed-Ashraf273 Mar 4, 2026
5c134eb
modify patcher
Mohamed-Ashraf273 Mar 4, 2026
f231bca
modify patcher
Mohamed-Ashraf273 Mar 4, 2026
8f18ff5
fix issues
Mohamed-Ashraf273 Mar 5, 2026
5049ce3
update test
Mohamed-Ashraf273 Mar 5, 2026
722dc53
update tests
Mohamed-Ashraf273 Mar 6, 2026
28a6330
fix test issue
Mohamed-Ashraf273 Mar 6, 2026
07efafd
fix test issue
Mohamed-Ashraf273 Mar 6, 2026
c52c62a
fix tests
Mohamed-Ashraf273 Mar 9, 2026
a63a52d
fix conflict
Mohamed-Ashraf273 Mar 9, 2026
f8bdfe5
fix conflict
Mohamed-Ashraf273 Mar 9, 2026
8228058
Merge branch 'main' into support_gigachat3
Mohamed-Ashraf273 Mar 9, 2026
5b32d32
revert conevrt.py changes
Mohamed-Ashraf273 Mar 13, 2026
04b4d9f
revert conevrt.py changes
Mohamed-Ashraf273 Mar 13, 2026
c0ba5d0
revert conevrt.py changes
Mohamed-Ashraf273 Mar 13, 2026
63a956d
revert conevrt.py changes
Mohamed-Ashraf273 Mar 13, 2026
acd8148
revert conevrt.py changes
Mohamed-Ashraf273 Mar 13, 2026
dbc1432
update deepseek's patcher
Mohamed-Ashraf273 Mar 15, 2026
47d2910
modify patcher
Mohamed-Ashraf273 Mar 17, 2026
eb601d9
update patcher
Mohamed-Ashraf273 Mar 20, 2026
fe1b84a
removed unnecessary check
Mohamed-Ashraf273 Mar 23, 2026
e86e7d9
fix pacther
Mohamed-Ashraf273 Mar 23, 2026
cbc2005
fix version
Mohamed-Ashraf273 Mar 23, 2026
199da92
fix version
Mohamed-Ashraf273 Mar 23, 2026
1dee64c
revert refactoring
Mohamed-Ashraf273 Mar 23, 2026
225aed3
update doc
Mohamed-Ashraf273 Mar 23, 2026
4174478
modify based on review
Mohamed-Ashraf273 Mar 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/source/openvino/models.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Here is the list of the supported architectures :
- Falcon
- Falcon-Mamba
- Flaubert
- GigaChat3
- GLM-4
- GLM-Edge
- GPT-2
Expand Down
20 changes: 20 additions & 0 deletions optimum/exporters/openvino/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,27 @@ def export_from_model(
generation_config = getattr(model, "generation_config", None)
if generation_config is not None:
try:
# Preserve the original `transformers_version` from the source model's generation_config.json.
# Starting in transformers 4.50, _prepare_generation_config() applies model-default generation
# parameters (do_sample, temperature, top_p, …) when the user-provided GenerationConfig uses
# the global default value for those fields AND the stored `transformers_version` is >= 4.50.
# Exporting bumps the version to the current transformers release, which causes user-supplied
# params (e.g. do_sample=False) to be silently overridden by the model defaults at inference
# time. Preserving the original version keeps the OV model consistent with the PT original.
orig_transformers_version = getattr(generation_config, "transformers_version", None)
generation_config.save_pretrained(output)
if orig_transformers_version is not None:
import json as _json
from pathlib import Path as _Path

gen_cfg_path = _Path(output) / "generation_config.json"
if gen_cfg_path.exists():
with open(gen_cfg_path, "r", encoding="utf-8") as _f:
_cfg = _json.load(_f)
if _cfg.get("transformers_version") != orig_transformers_version:
_cfg["transformers_version"] = orig_transformers_version
with open(gen_cfg_path, "w", encoding="utf-8") as _f:
_json.dump(_cfg, _f, indent=2)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we avoid this change? This modifies the common code for all models, which is undesirable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your feedback!

I reverted the changes and set gen_config.do_sample = False specifically for deepseek in test_decoder.py.

Could you please take another look and let me know if anything else should be adjusted?

Thanks!

except Exception as exception:
logger.warning(
f"The generation config will not be saved, saving failed with following error:\n{exception}"
Expand Down
4 changes: 2 additions & 2 deletions optimum/exporters/openvino/model_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4081,8 +4081,8 @@ class M2M100OpenVINOConfig(BartOpenVINOConfig):
)
@register_in_tasks_manager("deepseek", *["text-generation", "text-generation-with-past"], library_name="transformers")
class DeepseekOpenVINOConfig(MiniCPM3OpenVINOConfig):
MIN_TRANSFORMERS_VERSION = "4.46.0"
MAX_TRANSFORMERS_VERSION = "4.53.3"
MIN_TRANSFORMERS_VERSION = "4.53.0"
MAX_TRANSFORMERS_VERSION = None
_MODEL_PATCHER = DeepseekPatcher


Expand Down
384 changes: 162 additions & 222 deletions optimum/exporters/openvino/model_patcher.py

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions tests/openvino/test_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase):
if is_transformers_version(">=", "4.46.0"):
SUPPORTED_ARCHITECTURES += ("glm", "mistral-nemo", "phimoe")

if is_transformers_version("<", "4.54.0"):
SUPPORTED_ARCHITECTURES += ("deepseek",)

# gptq and awq install disabled for windows test environment
if platform.system() != "Windows" and is_transformers_version("<", "4.56.0"):
SUPPORTED_ARCHITECTURES += ("opt_gptq", "mixtral_awq")

if is_transformers_version(">=", "4.53.0"):
SUPPORTED_ARCHITECTURES += ("deepseek", "gigachat3")

if is_transformers_version(">", "4.47"):
SUPPORTED_ARCHITECTURES += ("olmo2",)

Expand Down Expand Up @@ -230,6 +230,7 @@ class OVModelForCausalLMIntegrationTest(unittest.TestCase):
"minicpm3": 6,
"phimoe": 2,
"deepseek": 2,
"gigachat3": 2,
"opt_gptq": 12,
"mixtral_awq": 2,
"gemma3_text": 2,
Expand Down Expand Up @@ -290,11 +291,8 @@ def test_find_untested_architectures(self):

if "llama4_text" in supported_architectures:
supported_architectures.remove("llama4_text")
if is_transformers_version(">=", str(DeepseekOpenVINOConfig.MAX_TRANSFORMERS_VERSION)):
if "deepseek_v2" in supported_architectures:
supported_architectures.remove("deepseek_v2")
if "deepseek_v3" in supported_architectures:
supported_architectures.remove("deepseek_v3")
if is_transformers_version(">=", str(DeepseekOpenVINOConfig.MIN_TRANSFORMERS_VERSION)):
supported_architectures -= {"deepseek_v2", "deepseek_v3"}
if is_transformers_version("<", str(BitnetOpenVINOConfig.MIN_TRANSFORMERS_VERSION)):
supported_architectures -= {"bitnet"}
if is_transformers_version("<", str(LFM2OpenVINOConfig.MIN_TRANSFORMERS_VERSION)):
Expand Down Expand Up @@ -397,6 +395,12 @@ def test_compare_to_transformers(self, model_arch):
return

tokens = tokenizer(["Today is a nice day and I am longer", "This is me"], return_tensors="pt", padding=True)

# Gigachat3 tokenizer add token_type_ids which DeepSeekV3
# and similar models do not accept in generate(); strip it so both OV and PT calls succeed.
if model_arch in ["gigachat3"]:
tokens.pop("token_type_ids", None)

ov_model.generation_config.eos_token_id = None
transformers_model.generation_config.eos_token_id = None
ov_model.config.eos_token_id = None
Expand All @@ -413,10 +417,6 @@ def test_compare_to_transformers(self, model_arch):

ov_outputs = ov_model.generate(**tokens, generation_config=gen_config)

# TODO: add back once https://huggingface.co/katuni4ka/tiny-random-minicpm3/discussions/1 merged (for all models) as current modeling incompatible with transformers >= v4.49
if model_arch in {"deepseek"} and is_transformers_version(">=", "4.49"):
self.skipTest("Incompatible modeling code")

additional_inputs = {}
# gemma2 does not support dynamic cache, it is unfair to compare dynamic cache result vs hybrid cache,
# align cache representation in torch model
Expand Down Expand Up @@ -666,10 +666,6 @@ def test_beam_search(self, model_arch):
if model_arch in ["lfm2", "granitemoehybrid"]:
return

# TODO: add back once https://huggingface.co/katuni4ka/tiny-random-minicpm3/discussions/1 merged (for all models) as current modeling incompatible with transformers >= v4.49
if model_arch in {"deepseek"} and is_transformers_version(">=", "4.49"):
self.skipTest("Incompatible modeling code")

tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=model_arch in REMOTE_CODE_MODELS)
if model_arch == "persimmon":
tokenizer.pad_token_id = tokenizer.bos_token_id
Expand Down
3 changes: 3 additions & 0 deletions tests/openvino/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class ExportModelTest(unittest.TestCase):
if is_transformers_version(">=", "4.48.0"):
SUPPORTED_ARCHITECTURES.update({"cohere2": OVModelForCausalLM})

if is_transformers_version(">=", "4.53.0"):
SUPPORTED_ARCHITECTURES.update({"deepseek": OVModelForCausalLM, "gigachat3": OVModelForCausalLM})

if is_transformers_version(">=", "4.49"):
SUPPORTED_ARCHITECTURES.update({"zamba2": OVModelForCausalLM})

Expand Down
8 changes: 8 additions & 0 deletions tests/openvino/test_exporters_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ class OVCLIExportTestCase(unittest.TestCase):
]
)

if is_transformers_version(">=", "4.53.0"):
SUPPORTED_ARCHITECTURES.extend(
[
("text-generation-with-past", "gigachat3"),
]
)

if is_transformers_version(">=", "4.57.0"):
SUPPORTED_ARCHITECTURES.extend(
[
Expand Down Expand Up @@ -198,6 +205,7 @@ class OVCLIExportTestCase(unittest.TestCase):
"exaone4": 2,
"bitnet": 2,
"granitemoehybrid": 2,
"gigachat3": 2,
}

TOKENIZER_CHAT_TEMPLATE_TESTS_MODELS = {
Expand Down
9 changes: 6 additions & 3 deletions tests/openvino/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"deberta-v2": "optimum-intel-internal-testing/tiny-random-DebertaV2Model",
"decilm": "optimum-intel-internal-testing/tiny-random-decilm",
"deepseek": "optimum-intel-internal-testing/tiny-random-deepseek-v3",
"gigachat3": "optimum-intel-internal-testing/tiny-random-gigachat3",
"deit": "optimum-intel-internal-testing/tiny-random-DeiTModel",
"convnext": "optimum-intel-internal-testing/tiny-random-convnext",
"convnextv2": "optimum-intel-internal-testing/tiny-random-ConvNextV2Model",
Expand Down Expand Up @@ -372,6 +373,7 @@
"hunyuan_v1_dense": {"model": 32},
"qwen3_eagle3": {"model": 20},
"qwen3_next": {"model": 100},
"gigachat3": {"model": 58},
}

TEST_IMAGE_URL = "http://images.cocodataset.org/val2017/000000039769.jpg"
Expand All @@ -397,7 +399,6 @@
"exaone4",
"decilm",
"minicpm3",
"deepseek",
"qwen3_eagle3",
)

Expand Down Expand Up @@ -552,8 +553,10 @@ def get_supported_model_for_library(library_name):
if supported_model_type[model_type].get("openvino"):
export_config = next(iter(supported_model_type[model_type]["openvino"].values()))

min_transformers = str(getattr(export_config.func, "MIN_TRANSFORMERS_VERSION", "0"))
max_transformers = str(getattr(export_config.func, "MAX_TRANSFORMERS_VERSION", "999"))
raw_min = getattr(export_config.func, "MIN_TRANSFORMERS_VERSION", None)
raw_max = getattr(export_config.func, "MAX_TRANSFORMERS_VERSION", None)
min_transformers = str(raw_min) if raw_min is not None else "0"
max_transformers = str(raw_max) if raw_max is not None else "999"

if is_transformers_version(">=", min_transformers) and is_transformers_version("<=", max_transformers):
valid_model.add(model_type)
Expand Down
Loading