Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions auto_round/compressors/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2527,9 +2527,9 @@ def _get_current_num_elm(
def _quantize_block(
self,
block: torch.nn.Module,
input_ids: list[torch.Tensor],
input_ids: Union[list[torch.Tensor], dict],
input_others: dict,
q_input: Union[None, torch.Tensor] = None,
q_input: Union[torch.Tensor, dict, None] = None,
device: Union[str, torch.device] = "cpu",
):
"""Quantize the weights of a given block of the model.
Expand Down Expand Up @@ -2646,7 +2646,11 @@ def _quantize_block(
else:
lr_schedule = copy.deepcopy(self.lr_scheduler)

nsamples = len(input_ids)
if isinstance(input_ids, dict): # input_ids of Flux is dict
nsamples = len(input_ids["hidden_states"])
else:
nsamples = len(input_ids)

pick_samples = self.batch_size * self.gradient_accumulate_steps
pick_samples = min(nsamples, pick_samples)
if self.sampler != "rand":
Expand Down
7 changes: 5 additions & 2 deletions auto_round/compressors/diffusion/compressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def _get_current_q_output(
def _get_block_outputs(
self,
block: torch.nn.Module,
input_ids: torch.Tensor,
input_ids: Union[torch.Tensor, dict],
input_others: torch.Tensor,
bs: int,
device: Union[str, torch.device],
Expand All @@ -233,8 +233,11 @@ def _get_block_outputs(
"""

output = defaultdict(list)
nsamples = len(input_ids)
output_config = output_configs.get(block.__class__.__name__, [])
if isinstance(input_ids, dict):
nsamples = len(input_ids["hidden_states"])
else:
nsamples = len(input_ids)

for i in range(0, nsamples, bs):
end_index = min(nsamples, i + bs)
Expand Down