Skip to content

Commit 1e647fc

Browse files
author
Amit Raj
committed
Comments addressed-2
Signed-off-by: Amit Raj <amitraj@qti.qualcommm.com>
1 parent 8f9cdf0 commit 1e647fc

File tree

3 files changed

+98
-3
lines changed

3 files changed

+98
-3
lines changed

QEfficient/base/modeling_qeff.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,19 @@ def model_name(self) -> str:
135135
mname = mname[4:]
136136
return mname
137137

138-
# TODO: Make get_model_config method abstract
139138
@property
139+
@abstractmethod
140140
def get_model_config(self) -> Dict:
141141
"""
142142
Get the model configuration as a dictionary.
143143
144+
This is an abstract property that must be implemented by all subclasses.
145+
Typically returns: self.model.config.__dict__
146+
144147
Returns:
145-
Dict: The configuration dictionary of the underlying HuggingFace model
148+
Dict: The configuration dictionary of the underlying model
146149
"""
147-
return self.model.config.__dict__
150+
pass
148151

149152
@abstractmethod
150153
def export(self, export_dir: Optional[str] = None) -> Path:

QEfficient/diffusers/pipelines/pipeline_module.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ class QEffTextEncoder(QEFFBaseModel):
4444
_pytorch_transforms = [CustomOpsTransform, T5ModelTransform]
4545
_onnx_transforms = [FP16ClipTransform, SplitTensorsTransform]
4646

47+
@property
48+
def get_model_config(self) -> Dict:
49+
"""
50+
Get the model configuration as a dictionary.
51+
52+
Returns:
53+
Dict: The configuration dictionary of the underlying text encoder model
54+
"""
55+
return self.model.config.__dict__
56+
4757
def __init__(self, model: nn.Module) -> None:
4858
"""
4959
Initialize the text encoder wrapper.
@@ -143,6 +153,16 @@ class QEffUNet(QEFFBaseModel):
143153
_pytorch_transforms = [CustomOpsTransform]
144154
_onnx_transforms = [FP16ClipTransform, SplitTensorsTransform]
145155

156+
@property
157+
def get_model_config(self) -> Dict:
158+
"""
159+
Get the model configuration as a dictionary.
160+
161+
Returns:
162+
Dict: The configuration dictionary of the underlying UNet model
163+
"""
164+
return self.model.config.__dict__
165+
146166
def __init__(self, model: nn.Module) -> None:
147167
"""
148168
Initialize the UNet wrapper.
@@ -211,6 +231,16 @@ class QEffVAE(QEFFBaseModel):
211231
_pytorch_transforms = [CustomOpsTransform]
212232
_onnx_transforms = [FP16ClipTransform, SplitTensorsTransform]
213233

234+
@property
235+
def get_model_config(self) -> Dict:
236+
"""
237+
Get the model configuration as a dictionary.
238+
239+
Returns:
240+
Dict: The configuration dictionary of the underlying VAE model
241+
"""
242+
return self.model.config.__dict__
243+
214244
def __init__(self, model: nn.Module, type: str) -> None:
215245
"""
216246
Initialize the VAE wrapper.
@@ -314,6 +344,16 @@ class QEffFluxTransformerModel(QEFFBaseModel):
314344
_pytorch_transforms = [AttentionTransform, NormalizationTransform, CustomOpsTransform]
315345
_onnx_transforms = [FP16ClipTransform, SplitTensorsTransform]
316346

347+
@property
348+
def get_model_config(self) -> Dict:
349+
"""
350+
Get the model configuration as a dictionary.
351+
352+
Returns:
353+
Dict: The configuration dictionary of the underlying Flux transformer model
354+
"""
355+
return self.model.config.__dict__
356+
317357
def __init__(self, model: nn.Module) -> None:
318358
"""
319359
Initialize the Flux transformer wrapper.

QEfficient/transformers/models/modeling_auto.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,18 @@ def from_pretrained(cls, pretrained_model_name_or_path, pooling=None, *args, **k
289289

290290
return cls(model, pretrained_model_name_or_path=pretrained_model_name_or_path, pooling=pooling, **kwargs)
291291

292+
@property
293+
def get_model_config(self) -> dict:
294+
"""
295+
Get the model configuration as a dictionary.
296+
297+
Returns
298+
-------
299+
dict
300+
The configuration dictionary of the underlying HuggingFace model.
301+
"""
302+
return self.model.config.__dict__
303+
292304
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
293305
"""
294306
Export the model to ONNX format using ``torch.onnx.export``.
@@ -2026,6 +2038,18 @@ def cloud_ai_100_generate(
20262038
),
20272039
)
20282040

2041+
@property
2042+
def get_model_config(self) -> dict:
2043+
"""
2044+
Get the configuration dictionary of the underlying HuggingFace model.
2045+
2046+
Returns
2047+
-------
2048+
dict
2049+
The configuration dictionary.
2050+
"""
2051+
return self.model.config.__dict__
2052+
20292053

20302054
class QEFFAutoModelForImageTextToText:
20312055
"""
@@ -2394,6 +2418,18 @@ def from_pretrained(
23942418
**kwargs,
23952419
)
23962420

2421+
@property
2422+
def get_model_config(self) -> dict:
2423+
"""
2424+
Get the model configuration as a dictionary.
2425+
2426+
Returns
2427+
-------
2428+
dict
2429+
The configuration dictionary of the underlying HuggingFace model.
2430+
"""
2431+
return self.model.config.__dict__
2432+
23972433
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False, **kwargs) -> str:
23982434
"""
23992435
Export the model to ONNX format using ``torch.onnx.export``.
@@ -3101,6 +3137,18 @@ def __init__(self, model: nn.Module, **kwargs):
31013137
self.num_layers = model.config.num_hidden_layers
31023138
self.hash_params["qeff_auto_class"] = self.__class__.__name__
31033139

3140+
@property
3141+
def get_model_config(self) -> dict:
3142+
"""
3143+
Get the configuration dictionary of the underlying HuggingFace model.
3144+
3145+
Returns
3146+
-------
3147+
dict
3148+
The configuration dictionary.
3149+
"""
3150+
return self.model.config.__dict__
3151+
31043152
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
31053153
"""
31063154
Export the model to ONNX format using ``torch.onnx.export``.
@@ -3473,6 +3521,10 @@ def from_pretrained(cls, pretrained_model_name_or_path, pooling=None, *args, **k
34733521

34743522
return cls(model, pretrained_model_name_or_path=pretrained_model_name_or_path, pooling=pooling, **kwargs)
34753523

3524+
@property
3525+
def get_model_config(self) -> dict:
3526+
return self.model.config.__dict__
3527+
34763528
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
34773529
"""
34783530
Exports the model to ``ONNX`` format using ``torch.onnx.export``.

0 commit comments

Comments
 (0)