-
Notifications
You must be signed in to change notification settings - Fork 216
Refined QDQ recipes of BERT/CLIP/VIT for QC and AMD. #1797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lintrunner found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since these are all new files, are still keeping the old qdq config jsons?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumping this again. Are we keeping both the old and new qdq configs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For others, we could take time to merge if feel needed
b38f396
to
1d827ae
Compare
|
||
subset = kwargs.get("subset") | ||
split = kwargs.get("split", "train") | ||
ds = load_dataset(dataset, name=subset, split=split) |
Check warning
Code scanning / lintrunner
PYLINT/W0621 Warning
See redefined-outer-name.
|
||
# Save the dataset to CSV | ||
data_frame = ds.to_pandas() | ||
print(f"Dataset size: {len(data_frame)}") |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
# Save the dataset to CSV | ||
data_frame = ds.to_pandas() | ||
print(f"Dataset size: {len(data_frame)}") | ||
print(data_frame.head()) |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
print(data_frame.head()) | ||
|
||
data_frame.to_csv(args.output_csv, index=False) | ||
print(f"Dataset saved to {args.output_csv}") |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
5860e49
to
b8e068d
Compare
@jambayk I think the lint errors are false alarms, do you have any ideas/suggestions? |
@Registry.register_post_process() | ||
def bert_scl_post_process(outputs): | ||
"""Post-processing for Sequence Classification task.""" | ||
match outputs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Olive still supports python 3.9 so this syntax is invalid. lint fails because of this.
20a6c6f
to
b4d82b1
Compare
{ "surgeon": "MatMulAddToGemm" } | ||
] | ||
}, | ||
"transformer_optimizer": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might not be required? with opset 20, the model gets exported with layernorm operator and quant_preprocess in onnxstatic quantization performs gelu fusion automatically
"type": "GraphSurgeries", | ||
"surgeries": [ | ||
{ "surgeon": "ReplaceAttentionMaskValue", "replacement": -100.0 }, | ||
{ "surgeon": "MatMulAddToGemm" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also add this new surgery "PowReduceSumPowDiv2LpNorm"
for the clip models?
"type": "GraphSurgeries", | ||
"surgeries": [ | ||
{ "surgeon": "ReplaceAttentionMaskValue", "replacement": -100.0 }, | ||
{ "surgeon": "MatMulAddToGemm" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works well for qc. not sure if it's recommended for amd.
"model_script": "google_bert_script.py" | ||
}, | ||
"passes": { | ||
"conversion": { "type": "OnnxConversion", "target_opset": 20, "dynamic": true, "use_dynamo_exporter": false }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dynamic and use_dynamo_exporter options are not required
return Dataset.from_pandas(pd.DataFrame(data)) | ||
|
||
|
||
def parse_args(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need this and the main part?
"model_type": "bert", | ||
"opt_level": 1, | ||
"optimization_options": { | ||
"enable_gelu": false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will not compile on AMD NPU
e259c65
to
5e394d6
Compare
) | ||
) | ||
|
||
print("Text encoding latency", model.text_model.latency) |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
) | ||
|
||
print("Text encoding latency", model.text_model.latency) | ||
print("Image encoding latency", model.vision_model.latency) |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
args.tokenizer, | ||
) | ||
|
||
print("Evaluation result", format_output(result)) |
Check warning
Code scanning / lintrunner
RUFF/T201 Warning
See https://docs.astral.sh/ruff/rules/print
|
||
def prepare_session( | ||
self, | ||
inference_settings: Optional[dict[str, Any]] = None, |
Check warning
Code scanning / lintrunner
RUFF/UP007 Warning
See https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
self, | ||
inference_settings: Optional[dict[str, Any]] = None, | ||
device: Device = Device.CPU, | ||
execution_providers: Optional[Union[str, list[str]]] = None, |
Check warning
Code scanning / lintrunner
RUFF/UP007 Warning
See https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
self, | ||
inference_settings: Optional[dict[str, Any]] = None, | ||
device: Device = Device.CPU, | ||
execution_providers: Optional[Union[str, list[str]]] = None, |
Check warning
Code scanning / lintrunner
RUFF/UP007 Warning
See https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
inference_settings: Optional[dict[str, Any]] = None, | ||
device: Device = Device.CPU, | ||
execution_providers: Optional[Union[str, list[str]]] = None, | ||
rank: Optional[int] = None, |
Check warning
Code scanning / lintrunner
RUFF/UP007 Warning
See https://docs.astral.sh/ruff/rules/non-pep604-annotation-union
**model.config.to_dict(), | ||
**(self.model_attributes or {}), | ||
} | ||
except Exception as _: |
Check notice
Code scanning / CodeQL
Empty except Note
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month ago
To fix the issue, we should handle the exception appropriately by logging the error. This ensures that any failure during the assignment to self.model_attributes
is recorded, aiding in debugging and maintaining transparency. If the exception is non-critical, we can log it as a warning or info message. Additionally, we should add a comment explaining why the exception is being handled in this way.
-
Copy modified lines R183-R185
@@ -182,4 +182,5 @@ | ||
} | ||
except Exception as _: | ||
pass | ||
except Exception as e: | ||
# Log the exception to ensure visibility while allowing the program to continue. | ||
logger.warning("Failed to set model attributes from model.config: %s", str(e)) | ||
|
closing this is it has gone stale and new PRs related to this has merged or are open. |
Pull request was closed
Describe your changes
Checklist before requesting a review
lintrunner -a
(Optional) Issue link