Skip to content

Commit 86a2ba1

Browse files
committed
fix MultiModalDataset padding
1 parent 529d748 commit 86a2ba1

4 files changed

Lines changed: 17 additions & 0 deletions

File tree

angelslim/data/dataloader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def create_data_loader(
4343
inference_settings: Dict = None,
4444
use_audio_in_video: bool = False,
4545
model_name: str = None,
46+
quantization_config: str = None,
4647
) -> DataLoader:
4748
"""
4849
Create appropriate DataLoader based on data source
@@ -94,6 +95,7 @@ def create_data_loader(
9495
data_source=data_source,
9596
is_hf_dataset=not os.path.isfile(data_source),
9697
model_name=model_name,
98+
quantization_config=quantization_config,
9799
)
98100
elif data_type == "Text2ImageDataset":
99101
dataset = Text2ImageDataset(

angelslim/data/multimodal_dataset.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ def __init__(
3737
data_source: Union[str, Dict] = None,
3838
is_hf_dataset: bool = False,
3939
model_name: str = None,
40+
quantization_config: str = None,
4041
):
4142
super().__init__(processor, device, max_length)
4243
self.is_hf_dataset = is_hf_dataset
4344
self.model_name = model_name
45+
self.quant_algo = quantization_config.name if quantization_config else None
4446

4547
if is_hf_dataset:
4648
self._load_hf_dataset(data_source, num_samples)
@@ -174,13 +176,21 @@ def _load_hf_dataset(self, dataset: str, num_samples: int):
174176

175177
def _process_and_append(self, messages: List[Dict], tools=None):
176178
"""Process messages and append to dataset"""
179+
180+
# max_length padding for gptq and awq
181+
if "gptq" in self.quant_algo or "awq" in self.quant_algo:
182+
padding = "max_length"
183+
else:
184+
padding = True
185+
177186
if self.model_name in ["Qwen3VL", "Qwen3VLMoE"]:
178187
inputs = self.processor.apply_chat_template(
179188
messages,
180189
tools=tools,
181190
tokenize=True,
182191
add_generation_prompt=True,
183192
return_dict=True,
193+
padding=padding,
184194
truncation=True,
185195
return_tensors="pt",
186196
max_length=self.max_length,
@@ -195,6 +205,7 @@ def _process_and_append(self, messages: List[Dict], tools=None):
195205
inputs = self.processor(
196206
text=[text],
197207
images=image_inputs,
208+
padding=padding,
198209
truncation=True,
199210
return_tensors="pt",
200211
max_length=self.max_length,
@@ -212,6 +223,7 @@ def _process_and_append(self, messages: List[Dict], tools=None):
212223
text=[text],
213224
images=image_inputs,
214225
videos=video_inputs,
226+
padding=padding,
215227
truncation=True,
216228
return_tensors="pt",
217229
max_length=self.max_length,

angelslim/engine.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def prepare_data(
149149
inference_settings=None,
150150
use_audio_in_video=False,
151151
model_name=None,
152+
quantization_config=None,
152153
) -> Optional[Any]:
153154
"""Prepare compression dataset"""
154155
if custom_dataloader is not None:
@@ -174,6 +175,7 @@ def prepare_data(
174175
inference_settings=inference_settings,
175176
use_audio_in_video=use_audio_in_video,
176177
model_name=model_name,
178+
quantization_config=quantization_config,
177179
)
178180
self.max_seq_length = max_length
179181

tools/run.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def run(config):
169169
inference_settings=dataset_config.inference_settings,
170170
use_audio_in_video=model_config.use_audio_in_video,
171171
model_name=model_config.name,
172+
quantization_config=compress_config.quantization,
172173
)
173174

174175
# Step 5: Initialize compressor

0 commit comments

Comments
 (0)