-
Notifications
You must be signed in to change notification settings - Fork 75
Description
Describe the bug
For efficient transformer branch release/v1.20.0
In several classes, ONNX export forwards export_dir positionally to _export(...).
However, _export’s signature places export_dir as the 6th parameter—after export_kwargs and onnx_transform_kwargs**, So the positional value binds to the wrong parameter (export_kwargs) and the actual export_dir remains None`.
As a result, a user-specified export directory is ignored, and exports go to the default location (QEFF_HOME / <model_name> with -<model_hash> suffix).
_export signature:
def _export(
self,
example_inputs: Dict[str, torch.Tensor],
output_names: List[str],
dynamic_axes: Dict[str, Dict[int, str]],
export_kwargs: Optional[Dict[str, any]] = None,
onnx_transform_kwargs: Optional[Dict[str, any]] = None,
export_dir: Optional[str] = None,
)
In several places export_dir is passed positionally:
self.vision_model.export(inputs["vision"],output_names["vision"], dynamic_axes["vision"], export_dir)
self.lang_model.export(inputs["lang"], output_names["lang"], dynamic_axes["lang"], export_dir)
def export(self, inputs, output_names, dynamic_axes, export_dir=None):
return self._export(inputs, output_names, dynamic_axes, export_dir)
List of classes where this pattern appears:
QEffVisionEncoderForTextImageToTextModel,
QEffCausalLMForTextImageToTextModel,
_QEffAutoModelForImageTextToTextDualQPC
Other classes like _QEFFAutoModelForImageTextToTextSingleQPC already use the correct, safe pattern:
def export(
self,
export_dir: Optional[str] = None,
**kwargs,
) -> str:
inputs = self.model.get_dummy_inputs()
dynamic_axes = self.model.get_onnx_dynamic_axes()
output_names = self.model.get_output_names()
return self._export(inputs, output_names, dynamic_axes, export_dir=export_dir)
Use keyword argument for export_dir in ONNX export calls to avoid positional misbinding.
To Reproduce
- Call any affected export(...) with a non-default export_dir, e.g. /home/tmp.
- Observe that the resulting ONNX artifacts are produced under the default path (QEFF_HOME / <model_name>-/...) instead of the provided /home/tmp/-/....
This happens because the positional argument is bound to export_kwargs, while export_dir remains None.
Expected behavior
All onnx export calls should use the keyword arguments for export_dir.
export_dir=export_dir