-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# ------------------------------------------------------------------------- | ||
Check warning Code scanning / lintrunner RUFF/format Warning test
Run lintrunner -a to apply this patch.
Check warning Code scanning / lintrunner BLACK-ISORT/format Warning test
Run lintrunner -a to apply this patch.
Check warning Code scanning / lintrunner EDITORCONFIG-CHECKER/editorconfig Warning test
Final newline expected
|
||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# -------------------------------------------------------------------------- | ||
from olive.model.handler.onnx import ONNXModelHandler | ||
from olive.passes.olive_pass import create_pass_from_dict | ||
from olive.passes.onnx.float32_conversion import OnnxIOFloat16ToFloat32 | ||
from test.unit_test.utils import get_onnx_model | ||
Check notice Code scanning / CodeQL Unused import Note test
Import of 'get_onnx_model' is not used.
Check warning Code scanning / lintrunner RUFF/F401 Warning test
test.unit\_test.utils.get\_onnx\_model imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import Check notice Code scanning / lintrunner PYLINT/C0411 Note test
standard import "test.unit_test.utils.get_onnx_model" should be placed before first party imports "olive.model.handler.onnx.ONNXModelHandler", "olive.passes.olive_pass.create_pass_from_dict", "olive.passes.onnx.float32_conversion.OnnxIOFloat16ToFloat32" (wrong-import-order)
See wrong-import-order. Check warning Code scanning / lintrunner PYLINT/W0611 Warning test
Unused get_onnx_model imported from test.unit_test.utils (unused-import)
See unused-import. |
||
import onnx | ||
Check notice Code scanning / lintrunner PYLINT/C0411 Note test
third party import "onnx" should be placed before first party imports "olive.model.handler.onnx.ONNXModelHandler", "olive.passes.olive_pass.create_pass_from_dict", "olive.passes.onnx.float32_conversion.OnnxIOFloat16ToFloat32" (wrong-import-order)
See wrong-import-order. |
||
from onnx import helper | ||
Check notice Code scanning / lintrunner PYLINT/C0411 Note test
third party import "onnx.helper" should be placed before first party imports "olive.model.handler.onnx.ONNXModelHandler", "olive.passes.olive_pass.create_pass_from_dict", "olive.passes.onnx.float32_conversion.OnnxIOFloat16ToFloat32" (wrong-import-order)
See wrong-import-order. |
||
from onnx import TensorProto | ||
Check notice Code scanning / lintrunner PYLINT/C0411 Note test
third party import "onnx.TensorProto" should be placed before first party imports "olive.model.handler.onnx.ONNXModelHandler", "olive.passes.olive_pass.create_pass_from_dict", "olive.passes.onnx.float32_conversion.OnnxIOFloat16ToFloat32" (wrong-import-order)
See wrong-import-order. |
||
|
||
|
||
def test_onnx_io_ft16_to_ft32_conversion(tmp_path): | ||
# setup | ||
node1 = helper.make_node( | ||
'Add', | ||
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
['logits_A', 'logits_B'], | ||
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
['logits_C'], | ||
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
name='add_node' | ||
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
) | ||
|
||
input_tensor_A = helper.make_tensor_value_info('logits_A', TensorProto.FLOAT16, [None]) | ||
Check warning Code scanning / lintrunner RUFF/N806 Warning test
Variable input\_tensor\_A in function should be lowercase.
See https://docs.astral.sh/ruff/rules/non-lowercase-variable-in-function Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
input_tensor_B = helper.make_tensor_value_info('logits_B', TensorProto.FLOAT16, [None]) | ||
Check warning Code scanning / lintrunner RUFF/N806 Warning test
Variable input\_tensor\_B in function should be lowercase.
See https://docs.astral.sh/ruff/rules/non-lowercase-variable-in-function Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
output_tensor_C = helper.make_tensor_value_info('logits_C', TensorProto.FLOAT16, [None]) | ||
Check warning Code scanning / lintrunner RUFF/N806 Warning test
Variable output\_tensor\_C in function should be lowercase.
See https://docs.astral.sh/ruff/rules/non-lowercase-variable-in-function Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
|
||
graph = helper.make_graph( | ||
[node1], | ||
Check failure Code scanning / lintrunner SPACES/trailing spaces Error test
This line has trailing spaces; please remove them.
Check warning Code scanning / lintrunner RUFF/W291 Warning test
Trailing whitespace.
See https://docs.astral.sh/ruff/rules/trailing-whitespace Check warning Code scanning / lintrunner EDITORCONFIG-CHECKER/editorconfig Warning test
Trailing whitespace
|
||
'example_graph', | ||
Check failure Code scanning / lintrunner SPACES/trailing spaces Error test
This line has trailing spaces; please remove them.
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string Check warning Code scanning / lintrunner RUFF/W291 Warning test
Trailing whitespace.
See https://docs.astral.sh/ruff/rules/trailing-whitespace Check warning Code scanning / lintrunner EDITORCONFIG-CHECKER/editorconfig Warning test
Trailing whitespace
|
||
[input_tensor_A, input_tensor_B], | ||
Check failure Code scanning / lintrunner SPACES/trailing spaces Error test
This line has trailing spaces; please remove them.
Check warning Code scanning / lintrunner RUFF/W291 Warning test
Trailing whitespace.
See https://docs.astral.sh/ruff/rules/trailing-whitespace Check warning Code scanning / lintrunner EDITORCONFIG-CHECKER/editorconfig Warning test
Trailing whitespace
|
||
[output_tensor_C] | ||
) | ||
onnx_model = helper.make_model(graph, producer_name='example_producer') | ||
Check warning Code scanning / lintrunner RUFF/Q000 Warning test
Single quotes found but double quotes preferred.
See https://docs.astral.sh/ruff/rules/bad-quotes-inline-string |
||
tmp_model_path = str(tmp_path / "model.onnx") | ||
onnx.save(onnx_model, tmp_model_path) | ||
input_model = ONNXModelHandler(model_path=tmp_model_path) | ||
p = create_pass_from_dict(OnnxIOFloat16ToFloat32, None, disable_search=True) | ||
output_folder = str(tmp_path / "onnx") | ||
|
||
# execute | ||
output_model = p.run(input_model, None, output_folder) | ||
|
||
# assert | ||
for input in output_model.get_graph().input: | ||
Check warning Code scanning / lintrunner RUFF/A001 Warning test
Variable input is shadowing a Python builtin.
See https://docs.astral.sh/ruff/rules/builtin-variable-shadowing Check warning Code scanning / lintrunner PYLINT/W0622 Warning test
Redefining built-in 'input' (redefined-builtin)
See redefined-builtin. |
||
assert input.type.tensor_type.elem_type == onnx.TensorProto.FLOAT | ||
for output in output_model.get_graph().output: | ||
assert output.type.tensor_type.elem_type == onnx.TensorProto.FLOAT | ||
Check warning Code scanning / lintrunner RUFF/W292 Warning test
No newline at end of file.
See https://docs.astral.sh/ruff/rules/missing-newline-at-end-of-file |