Skip to content

Commit e822679

Browse files
author
Amit Raj
committed
Comments addressed-2
Signed-off-by: Amit Raj <[email protected]>
1 parent 26e8368 commit e822679

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``.
@@ -2059,6 +2071,18 @@ def cloud_ai_100_generate(
20592071
),
20602072
)
20612073

2074+
@property
2075+
def get_model_config(self) -> dict:
2076+
"""
2077+
Get the configuration dictionary of the underlying HuggingFace model.
2078+
2079+
Returns
2080+
-------
2081+
dict
2082+
The configuration dictionary.
2083+
"""
2084+
return self.model.config.__dict__
2085+
20622086

20632087
class QEFFAutoModelForImageTextToText:
20642088
"""
@@ -2429,6 +2453,18 @@ def from_pretrained(
24292453
**kwargs,
24302454
)
24312455

2456+
@property
2457+
def get_model_config(self) -> dict:
2458+
"""
2459+
Get the model configuration as a dictionary.
2460+
2461+
Returns
2462+
-------
2463+
dict
2464+
The configuration dictionary of the underlying HuggingFace model.
2465+
"""
2466+
return self.model.config.__dict__
2467+
24322468
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False, **kwargs) -> str:
24332469
"""
24342470
Export the model to ONNX format using ``torch.onnx.export``.
@@ -3149,6 +3185,18 @@ def __init__(self, model: nn.Module, **kwargs):
31493185
self.num_layers = model.config.num_hidden_layers
31503186
self.hash_params["qeff_auto_class"] = self.__class__.__name__
31513187

3188+
@property
3189+
def get_model_config(self) -> dict:
3190+
"""
3191+
Get the configuration dictionary of the underlying HuggingFace model.
3192+
3193+
Returns
3194+
-------
3195+
dict
3196+
The configuration dictionary.
3197+
"""
3198+
return self.model.config.__dict__
3199+
31523200
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
31533201
"""
31543202
Export the model to ONNX format using ``torch.onnx.export``.
@@ -3521,6 +3569,10 @@ def from_pretrained(cls, pretrained_model_name_or_path, pooling=None, *args, **k
35213569

35223570
return cls(model, pretrained_model_name_or_path=pretrained_model_name_or_path, pooling=pooling, **kwargs)
35233571

3572+
@property
3573+
def get_model_config(self) -> dict:
3574+
return self.model.config.__dict__
3575+
35243576
def export(self, export_dir: Optional[str] = None, use_onnx_subfunctions: bool = False) -> str:
35253577
"""
35263578
Exports the model to ``ONNX`` format using ``torch.onnx.export``.

0 commit comments

Comments
 (0)