Skip to content

Commit 0d502f6

Browse files
committed
move around imports
1 parent aca3244 commit 0d502f6

File tree

3 files changed

+13
-31
lines changed

3 files changed

+13
-31
lines changed

src/llmcompressor/modeling/prepare.py

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,12 @@
11
import tqdm
22
from compressed_tensors.utils import replace_module
3-
from loguru import logger
43
from transformers import PreTrainedModel
54

65
from llmcompressor.modeling.deepseek_v3 import replace as replace_deepseekv3
76
from llmcompressor.modeling.llama4 import replace as replace_llama4
87
from llmcompressor.modeling.qwen3_moe import replace as replace_Qwen3MoE
9-
10-
try:
11-
from llmcompressor.modeling.qwen3_next_moe import replace as replace_Qwen3NextMoE
12-
from llmcompressor.modeling.qwen3_vl_moe import replace as replace_Qwen3VLMoE
13-
except ImportError:
14-
logger.warning(
15-
"Qwen3-VL-MoE and Qwen3-Next support is not available. "
16-
"Please ensure that you have the correct version of transformers installed."
17-
)
18-
replace_Qwen3VLMoE = None
19-
replace_Qwen3NextMoE = None
20-
8+
from llmcompressor.modeling.qwen3_next_moe import replace as replace_Qwen3NextMoE
9+
from llmcompressor.modeling.qwen3_vl_moe import replace as replace_Qwen3VLMoE
2110
from llmcompressor.utils.helpers import patch_attr
2211

2312
__all__ = ["replace_modules_for_calibration"]
@@ -26,11 +15,9 @@
2615
replacements = {
2716
"DeepseekV3MoE": replace_deepseekv3,
2817
"Llama4TextMoe": replace_llama4,
18+
"Qwen3VLMoeTextSparseMoeBlock": replace_Qwen3VLMoE,
2919
}
3020

31-
if replace_Qwen3VLMoE is not None:
32-
replacements["Qwen3VLMoeTextSparseMoeBlock"] = replace_Qwen3VLMoE
33-
3421

3522
def replace_modules_for_calibration(
3623
model: PreTrainedModel,
@@ -92,11 +79,9 @@ def update_qwen3_next_moe(model, module, stack, calibrate_all_experts):
9279

9380
moe_context = {
9481
"Qwen3MoeForCausalLM": update_qwen3_moe,
82+
"Qwen3NextForCausalLM": update_qwen3_next_moe,
9583
}
9684

97-
if replace_Qwen3NextMoE is not None:
98-
moe_context["Qwen3NextForCausalLM"] = update_qwen3_next_moe
99-
10085

10186
def moe_calibration_context(
10287
model: PreTrainedModel,

src/llmcompressor/modeling/qwen3_next_moe.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,13 @@
1515
# limitations under the License.
1616

1717
import torch
18-
from transformers.models import Qwen3NextConfig
19-
from transformers.models.qwen3_next.modeling_qwen3_next import (
20-
Qwen3NextSparseMoeBlock as OriginalQwen3NextMoeSparseMoeBlock,
21-
)
2218

2319

2420
class Qwen3NextSparseMoeBlock(torch.nn.Module):
2521
def __init__(
2622
self,
27-
config: Qwen3NextConfig,
28-
original: OriginalQwen3NextMoeSparseMoeBlock,
23+
config,
24+
original,
2925
calibrate_all_experts: bool,
3026
):
3127
super().__init__()
@@ -109,9 +105,9 @@ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
109105

110106

111107
def replace(
112-
config: Qwen3NextConfig,
113-
module: OriginalQwen3NextMoeSparseMoeBlock,
114-
calibrate_all_experts: bool,
108+
config,
109+
module,
110+
calibrate_all_experts,
115111
):
116112
return Qwen3NextSparseMoeBlock(
117113
config=config, original=module, calibrate_all_experts=calibrate_all_experts

src/llmcompressor/modeling/qwen3_vl_moe.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import torch
2-
from transformers.models.qwen3_vl_moe.modeling_qwen3_vl_moe import (
3-
Qwen3VLMoeTextMLP,
4-
)
52

63
from llmcompressor.utils.dev import skip_weights_initialize
74

@@ -17,6 +14,10 @@ def __init__(self, config, original):
1714

1815
class SequentialQwen3VLMoeTextExperts(torch.nn.ModuleList):
1916
def __init__(self, config, original):
17+
from transformers.models.qwen3_vl_moe.modeling_qwen3_vl_moe import (
18+
Qwen3VLMoeTextMLP,
19+
)
20+
2021
self.num_experts = original.gate_up_proj.shape[0]
2122
with skip_weights_initialize():
2223
super().__init__(

0 commit comments

Comments
 (0)