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
28 changes: 22 additions & 6 deletions gptqmodel/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1244,14 +1244,30 @@ def get_base_modules(cls, model):
"""
Return list of base modules directly under 'model' but not 'model.layers'.
"""
root = cls.module_tree[0] # "model"
exclude = cls.module_tree[1] # "layers"
# Find the index of "#"
tree = cls.module_tree
try:
sharp_idx = tree.index("#")
except ValueError:
raise ValueError("module_tree must contain '#' to separate hierarchy")

assert sharp_idx > 0, "failed to get_base_modules"
# root_path = ["model"] or ["model", "language_model"]
root_path = tree[:sharp_idx-1]

base = getattr(model, root)
out = []
for name, _ in base.named_children():
if name != exclude: # skip second node which is parallel in scope
out.append(f"{root}.{name}")
# Traverse each layer in root_path
for i in range(len(root_path)):
path = root_path[:i + 1]
base = model
exclude = tree[len(path)]

for node in path:
base = getattr(base, node)

for name, _ in base.named_children():
if name != exclude:
out.append(".".join(path + [name]))

# print(f"Base Modules: {out}")
return out
Expand Down
2 changes: 1 addition & 1 deletion gptqmodel/models/definitions/base_qwen2_vl.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def preprocess_dataset(self, sample: Dict) -> Dict:
def load_processor(self) -> ProcessorMixin:
return AutoProcessor.from_pretrained(self.model_local_path)

def prepare_dataset(self, calibration_dataset, calibration_dataset_concat_size=None, batch_size: int = 1):
def prepare_dataset(self, calibration_dataset, batch_size: int = 1, **kwargs):
processor = self.load_processor()
calib_data = []
for batch in batched(calibration_dataset, batch_size, process_func=self.preprocess_dataset):
Expand Down