Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyasMoutawwakil committed Jul 30, 2024
1 parent e833ffc commit bb85fcd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion optimum_benchmark/backends/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def __init__(self, config: BackendConfigT):
self.generation_config = None
self.pretrained_config = None
self.automodel_loader = None
self.model_shapes = {}
# TOD: need a custom method to extract shapes from gguf
self.model_shapes = extract_transformers_shapes_from_artifacts(
self.pretrained_config, self.pretrained_processor
)

else:
self.logger.info("\t+ Benchmarking a Transformers model")
Expand Down
13 changes: 10 additions & 3 deletions optimum_benchmark/backends/transformers_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,19 @@ def get_transformers_pretrained_processor(model: str, **kwargs) -> Optional["Pre


def extract_transformers_shapes_from_artifacts(
config: "PretrainedConfig", processor: Optional["PretrainedProcessor"] = None
config: Optional["PretrainedConfig"] = None, processor: Optional["PretrainedProcessor"] = None
) -> Dict[str, Any]:
artifacts_dict = {}

config_dict = {k: v for k, v in config.to_dict().items() if v is not None}
artifacts_dict.update(config_dict)
if config is not None and hasattr(config, "to_dict"):
config_dict = {k: v for k, v in config.to_dict().items() if v is not None}
artifacts_dict.update(config_dict)
elif config is not None:
try:
config_dict = {k: getattr(config, k) for k in dir(config) if isinstance(getattr(config, k), int)}
artifacts_dict.update(config_dict)
except Exception:
warnings.warn(f"Could not extract shapes from config {config}")

if processor is not None and hasattr(processor, "to_dict"):
processor_dict = {k: v for k, v in processor.to_dict().items() if v is not None}
Expand Down

0 comments on commit bb85fcd

Please sign in to comment.