Skip to content

Commit e0562c6

Browse files
govind-ramnarayanbmarimuthu-nv
authored andcommitted
[None][fix] Remove HF cache dependency from Skywork-R1V2 unit tests (#242)
* [None][fix] Remove HF cache dependency from Skywork-R1V2 unit tests Replace SkyworkChatConfig (loaded via AutoConfig with trust_remote_code, which requires the checkpoint in the local HF cache) with a plain Qwen2Config passed directly to SkyworkR1V2ForConditionalGeneration. The model's __init__ already has a fallback: llm_config = getattr(config, "llm_config", config) so passing Qwen2Config directly works without any wrapper config. The vision tower is simply not instantiated (no vision_config attr). This makes all tests runnable in CI without requiring the full 38B checkpoint in the local HF cache. Signed-off-by: gramnarayan <105831528+govind-ramnarayan@users.noreply.github.com> * [None][fix] Remove HF cache dependency from Skywork-R1V2 unit tests Replace AutoConfig.from_pretrained(..., local_files_only=True) with minimal faithful copies of SkyworkChatConfig and SkyworkVisionConfig defined in the test file (same pattern used for HF modeling classes not in transformers). This removes the module-level pytest.skip that silently skipped all Skywork tests in CI when the 38B checkpoint was absent. Tests now run without any HF checkpoint, while still exercising the real config- wrapping behavior (nested llm_config, vision_config, vision weight keys). Signed-off-by: gramnarayan <105831528+govind-ramnarayan@users.noreply.github.com> --------- Signed-off-by: gramnarayan <105831528+govind-ramnarayan@users.noreply.github.com>
1 parent ed6b216 commit e0562c6

1 file changed

Lines changed: 82 additions & 26 deletions

File tree

tests/unittest/auto_deploy/singlegpu/models/test_skywork_r1v2_modeling.py

Lines changed: 82 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import torch
2828
from _model_test_utils import assert_rmse_close
2929
from torch.export import Dim
30-
from transformers import AutoConfig, Qwen2Config, Qwen2ForCausalLM
30+
from transformers import Qwen2Config, Qwen2ForCausalLM
31+
from transformers.modeling_utils import PretrainedConfig
3132
from transformers.models.qwen2.modeling_qwen2 import (
3233
Qwen2Attention,
3334
Qwen2DecoderLayer,
@@ -47,22 +48,77 @@
4748
)
4849
from tensorrt_llm._torch.auto_deploy.utils._graph import move_to_device
4950

50-
# Load SkyworkChatConfig the same way AutoDeploy's factory does: via AutoConfig with
51-
# trust_remote_code. Skip all tests if the checkpoint is not in the local HF cache.
52-
try:
53-
SkyworkChatConfig = type(
54-
AutoConfig.from_pretrained(
55-
"Skywork/Skywork-R1V2-38B", trust_remote_code=True, local_files_only=True
56-
)
57-
)
58-
except Exception:
59-
SkyworkChatConfig = None
51+
# ---------------------------------------------------------------------------
52+
# Minimal faithful copies of HF remote-code config classes
53+
# (SkyworkChatConfig / SkyworkVisionConfig use trust_remote_code and are not
54+
# in transformers; these copies are for test-only use)
55+
# ---------------------------------------------------------------------------
56+
57+
58+
class SkyworkVisionConfig(PretrainedConfig):
59+
"""Minimal faithful copy of SkyworkVisionConfig from HF checkpoint remote code."""
60+
61+
model_type = "skywork_vit"
62+
63+
def __init__(
64+
self,
65+
hidden_size=32,
66+
image_size=32,
67+
patch_size=16,
68+
num_attention_heads=2,
69+
intermediate_size=64,
70+
hidden_act="gelu",
71+
num_hidden_layers=1,
72+
qkv_bias=True,
73+
qk_normalization=False,
74+
layer_norm_eps=1e-6,
75+
norm_type="rms_norm",
76+
initializer_factor=0.1,
77+
**kwargs,
78+
):
79+
super().__init__(**kwargs)
80+
self.hidden_size = hidden_size
81+
self.image_size = image_size
82+
self.patch_size = patch_size
83+
self.num_attention_heads = num_attention_heads
84+
self.intermediate_size = intermediate_size
85+
self.hidden_act = hidden_act
86+
self.num_hidden_layers = num_hidden_layers
87+
self.qkv_bias = qkv_bias
88+
self.qk_normalization = qk_normalization
89+
self.layer_norm_eps = layer_norm_eps
90+
self.norm_type = norm_type
91+
self.initializer_factor = initializer_factor
92+
93+
94+
class SkyworkChatConfig(PretrainedConfig):
95+
"""Minimal faithful copy of SkyworkChatConfig from HF checkpoint remote code."""
96+
97+
model_type = "skywork_chat"
98+
99+
def __init__(
100+
self,
101+
llm_config=None,
102+
vision_config=None,
103+
select_layer=-1,
104+
downsample_ratio=0.5,
105+
ps_version="v1",
106+
tie_word_embeddings=False,
107+
**kwargs,
108+
):
109+
super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)
110+
if isinstance(llm_config, dict):
111+
llm_config = Qwen2Config(**{k: v for k, v in llm_config.items() if k != "model_type"})
112+
self.llm_config = llm_config
113+
if isinstance(vision_config, dict):
114+
vision_config = SkyworkVisionConfig(**vision_config)
115+
elif vision_config is None:
116+
vision_config = SkyworkVisionConfig()
117+
self.vision_config = vision_config
118+
self.select_layer = select_layer
119+
self.downsample_ratio = downsample_ratio
120+
self.ps_version = ps_version
60121

61-
if SkyworkChatConfig is None:
62-
pytest.skip(
63-
"Skywork/Skywork-R1V2-38B not found in local HF cache; skipping tests.",
64-
allow_module_level=True,
65-
)
66122

67123
_BATCH_AND_SEQUENCE_TEST_CASES = ((2, 6), (1, 8))
68124

@@ -80,7 +136,7 @@ def set_seed():
80136
def _create_small_llm_config() -> Qwen2Config:
81137
"""Create a small Qwen2 config for the LLM backbone (used by block/layer tests)."""
82138
return Qwen2Config(
83-
architectures=["Qwen2ForCausalLM"], # required by SkyworkChatConfig.__init__
139+
architectures=["Qwen2ForCausalLM"],
84140
vocab_size=1000,
85141
hidden_size=64,
86142
intermediate_size=128,
@@ -101,9 +157,10 @@ def _create_small_chat_config() -> SkyworkChatConfig:
101157
"""Create a small SkyworkChatConfig wrapping the Qwen2 LLM config.
102158
103159
Mirrors how AutoDeploy's factory builds the model: AutoConfig returns a
104-
SkyworkChatConfig, which is then passed to SkyworkR1V2ForConditionalGeneration._from_config.
105-
tie_word_embeddings is forwarded explicitly to prevent PretrainedConfig from
106-
defaulting to True and spuriously tying lm_head to embed_tokens.
160+
SkyworkChatConfig, which is then passed to
161+
SkyworkR1V2ForConditionalGeneration._from_config. tie_word_embeddings is
162+
forwarded explicitly to prevent PretrainedConfig from defaulting to True
163+
and spuriously tying lm_head to embed_tokens.
107164
"""
108165
llm_dict = _create_small_llm_config().to_dict()
109166
return SkyworkChatConfig(
@@ -389,7 +446,7 @@ def test_skywork_r1v2_state_dict_keys():
389446
"""Test that state_dict keys match expected checkpoint format.
390447
391448
With a full SkyworkChatConfig (which includes vision_config), the model also
392-
instantiates the vision tower and mlp1 projector. Their keys follow the HF
449+
instantiates the vision tower and mlp1 projector. Their keys follow the HF
393450
checkpoint layout: vision_model.* and mlp1.*.
394451
"""
395452
model = SkyworkR1V2ForConditionalGeneration(_create_small_chat_config())
@@ -429,21 +486,20 @@ def test_skywork_r1v2_state_dict_keys():
429486
"vision_model.encoder.layers.0.norm2.weight",
430487
"vision_model.encoder.layers.0.ls1",
431488
"vision_model.encoder.layers.0.ls2",
432-
"mlp1.0.weight", # LayerNorm
489+
"mlp1.0.weight",
433490
"mlp1.0.bias",
434-
"mlp1.1.weight", # Linear
491+
"mlp1.1.weight",
435492
"mlp1.1.bias",
436-
"mlp1.3.weight", # Linear
493+
"mlp1.3.weight",
437494
"mlp1.3.bias",
438495
]
439496
for key in expected_vision_keys:
440497
assert key in state_dict, (
441498
f"Expected vision key '{key}' in state_dict, got keys: {list(state_dict.keys())[:10]}..."
442499
)
443500

444-
# All keys must be under language_model.*, vision_model.*, or mlp1.*
445501
valid_prefixes = ("language_model.", "vision_model.", "mlp1.")
446502
for key in state_dict:
447-
assert any(key.startswith(p) for p in valid_prefixes), (
503+
assert any(key.startswith(prefix) for prefix in valid_prefixes), (
448504
f"Unexpected key '{key}' — expected prefix in {valid_prefixes}"
449505
)

0 commit comments

Comments
 (0)