Skip to content
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

[Test only] BFloat16 test for SkipSimplifiedLayerNormalization #22941

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jiafatom
Copy link
Contributor

Description

Motivation and Context

@jiafatom jiafatom changed the title BFloat16 test for SkipSimplifiedLayerNormalization [Test only] BFloat16 test for SkipSimplifiedLayerNormalization Nov 25, 2024
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Comment on lines 122 to 127
skip_size);
}
else
{
LaunchSkipLayerNormKernel<CudaT, Simplified>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
skip_size);
}
else
{
LaunchSkipLayerNormKernel<CudaT, Simplified>(
skip_size);
} else {
LaunchSkipLayerNormKernel<CudaT, Simplified>(

Comment on lines 18 to 22
import tempfile
from typing import Dict
from enum import Enum

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import tempfile
from typing import Dict
from enum import Enum
import tempfile
from enum import Enum
from typing import Dict

Comment on lines 24 to 27
from onnx import AttributeProto, GraphProto, ModelProto, NodeProto, TensorProto, helper, numpy_helper
from onnx.shape_inference import infer_shapes, infer_shapes_path
from onnx.helper import float32_to_bfloat16
from packaging import version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from onnx import AttributeProto, GraphProto, ModelProto, NodeProto, TensorProto, helper, numpy_helper
from onnx.shape_inference import infer_shapes, infer_shapes_path
from onnx.helper import float32_to_bfloat16
from packaging import version
from onnx import AttributeProto, GraphProto, ModelProto, NodeProto, TensorProto, helper, numpy_helper
from onnx.helper import float32_to_bfloat16
from onnx.shape_inference import infer_shapes, infer_shapes_path
from packaging import version

Comment on lines 40 to 47


def convert_np_to_float16(np_array, min_positive_val=5.96e-08, max_finite_val=65504.0):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def convert_np_to_float16(np_array, min_positive_val=5.96e-08, max_finite_val=65504.0):
def convert_np_to_float16(np_array, min_positive_val=5.96e-08, max_finite_val=65504.0):

Comment on lines 110 to +123

def convert_tensor_float_to_bfloat16(tensor):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def convert_tensor_float_to_bfloat16(tensor):
def convert_tensor_float_to_bfloat16(tensor):

Comment on lines +189 to +203
class NodeValueType(Enum):
FP32 = 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class NodeValueType(Enum):
FP32 = 1
class NodeValueType(Enum):

Comment on lines 194 to 208
class InitializerTracker:
"""Class for keeping track of initializer."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class InitializerTracker:
"""Class for keeping track of initializer."""
class InitializerTracker:

Comment on lines 211 to 225
def convert_float_to_float16(
model,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def convert_float_to_float16(
model,
def convert_float_to_float16(

Comment on lines 470 to 489

# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.
for node in mixed_float_type_node_list:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.
for node in mixed_float_type_node_list:
# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Comment on lines 18 to 23
import tempfile
from typing import Dict
from enum import Enum
import ml_dtypes

import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import tempfile
from typing import Dict
from enum import Enum
import ml_dtypes
import numpy as np
import tempfile
from enum import Enum
from typing import Dict
import ml_dtypes
import numpy as np

@jiafatom jiafatom force-pushed the skip_bf_16 branch 4 times, most recently from 03bf839 to 09e2cc1 Compare November 26, 2024 02:24
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Comment on lines +122 to +127
skip_size);
}
else
{
LaunchSkipLayerNormKernel<CudaT, Simplified>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
skip_size);
}
else
{
LaunchSkipLayerNormKernel<CudaT, Simplified>(
skip_size);
} else {
LaunchSkipLayerNormKernel<CudaT, Simplified>(

…lic_shape bugfix (#23558)

- Add symbolic shape inference dispatcher for `ReduceMean`.
- Reducemean is used in RMSNorm so shape inference fails for llama, phi,
etc torch exported models.
- Reuse the dispatcher for ReduceSum since ReduceMean 18+ and ReduceSum
13+ have the same specs other than the type of reduction done.
- Fix an issue with `quant_pre_process` tool where the external data
file is missing if `skip_symbolic_shape=True` and
`skip_optimization=False`.
- Add `"session.optimized_model_external_initializers_file_name"` to
session options so that the external data gets saved in the same temp
directory as the optimized model.

<!-- - Why is this change required? What problem does it solve?
- If it fixes an open issue, please link to the issue here. -->
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can commit the suggested changes from lintrunner.

Comment on lines 18 to 23
import tempfile
from typing import Dict
from enum import Enum
import ml_dtypes

import numpy as np
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import tempfile
from typing import Dict
from enum import Enum
import ml_dtypes
import numpy as np
import tempfile
from enum import Enum
import ml_dtypes
import numpy as np

Comment on lines 30 to 37

import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex
import onnxruntime as rt


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex
import onnxruntime as rt

Comment on lines 80 to 82

def convert_tensor_float_to_float16(tensor, min_positive_val=5.96e-08, max_finite_val=65504.0):
def convert_tensor_float_to_float16(tensor, is_value_type_bfloat16=False, min_positive_val=5.96e-08, max_finite_val=65504.0):
"""Convert tensor float to float16.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def convert_tensor_float_to_float16(tensor, min_positive_val=5.96e-08, max_finite_val=65504.0):
def convert_tensor_float_to_float16(tensor, is_value_type_bfloat16=False, min_positive_val=5.96e-08, max_finite_val=65504.0):
"""Convert tensor float to float16.
def convert_tensor_float_to_float16(
tensor, is_value_type_bfloat16=False, min_positive_val=5.96e-08, max_finite_val=65504.0
):
"""Convert tensor float to float16.

Comment on lines 201 to +202

class NodeValueType(Enum):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class NodeValueType(Enum):
class NodeValueType(Enum):

Comment on lines 206 to 207

class InitializerTracker:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class InitializerTracker:
class InitializerTracker:

Comment on lines +486 to 488


# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.
# Some operators have data type fixed as float for some input. Add a float16 to float cast for those inputs.

Comment on lines 502 to 504
node_name = node.name + "_input_cast" + str(i)
new_node = [helper.make_node("Cast", [input_name], [output_name], to=1, name=node_name)]
new_node = [helper.make_node("Cast", [input_name], [output_name], to=TensorProto.FLOAT, name=node_name)]
model.graph.node.extend(new_node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
node_name = node.name + "_input_cast" + str(i)
new_node = [helper.make_node("Cast", [input_name], [output_name], to=1, name=node_name)]
new_node = [helper.make_node("Cast", [input_name], [output_name], to=TensorProto.FLOAT, name=node_name)]
model.graph.node.extend(new_node)
node_name = node.name + "_input_cast" + str(i)
new_node = [
helper.make_node("Cast", [input_name], [output_name], to=TensorProto.FLOAT, name=node_name)
]
model.graph.node.extend(new_node)

Comment on lines +546 to 548
# new_node = [helper.make_node("Cast", [input_name], [output], to=final_value_type, name=node_name)]
new_node = [helper.make_node("Cast", [input_name], [output], to=TensorProto.FLOAT16, name=node_name)]
model.graph.node.extend(new_node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# new_node = [helper.make_node("Cast", [input_name], [output], to=final_value_type, name=node_name)]
new_node = [helper.make_node("Cast", [input_name], [output], to=TensorProto.FLOAT16, name=node_name)]
model.graph.node.extend(new_node)
# new_node = [helper.make_node("Cast", [input_name], [output], to=final_value_type, name=node_name)]
new_node = [
helper.make_node("Cast", [input_name], [output], to=TensorProto.FLOAT16, name=node_name)
]
model.graph.node.extend(new_node)

Comment on lines +556 to +558
# model = ir.serde.serialize_model(ir_model)
'''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# model = ir.serde.serialize_model(ir_model)
'''
# model = ir.serde.serialize_model(ir_model)
"""

Comment on lines +573 to +575
domain=model.domain)
'''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
domain=model.domain)
'''
domain=model.domain)
"""

@@ -16,6 +16,9 @@
import logging
import os
import tempfile
from typing import Dict

Check warning

Code scanning / lintrunner

RUFF/UP035 Warning

typing.Dict is deprecated, use dict instead.
See https://docs.astral.sh/ruff/rules/deprecated-import
@@ -16,6 +16,9 @@
import logging
import os
import tempfile
from typing import Dict

Check warning

Code scanning / lintrunner

RUFF/F401 Warning

typing.Dict imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript

Check warning

Code scanning / lintrunner

RUFF/E402 Warning

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript

Check warning

Code scanning / lintrunner

RUFF/I001 Warning

Import block is un-sorted or un-formatted.
See https://docs.astral.sh/ruff/rules/unsorted-imports
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript

Check warning

Code scanning / lintrunner

RUFF/F401 Warning

onnxscript imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common

Check warning

Code scanning / lintrunner

RUFF/F401 Warning

onnxconverter\_common imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import
import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex

Check warning

Code scanning / lintrunner

RUFF/E402 Warning

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex

Check warning

Code scanning / lintrunner

RUFF/F401 Warning

onnxconverter\_common.onnx\_ex.make\_model\_ex imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex
import onnxruntime as rt

Check warning

Code scanning / lintrunner

RUFF/E402 Warning

Module level import not at top of file.
See https://docs.astral.sh/ruff/rules/module-import-not-at-top-of-file
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex
import onnxruntime as rt

Check warning

Code scanning / lintrunner

RUFF/F401 Warning

onnxruntime imported but unused.
See https://docs.astral.sh/ruff/rules/unused-import
@@ -16,6 +16,9 @@
import logging
import os
import tempfile
from typing import Dict

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'Dict' is not used.
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'onnxscript' is not used.
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript
from onnxscript import optimizer, ir

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'optimizer' is not used.
Import of 'ir' is not used.
@@ -25,6 +28,12 @@

logger = logging.getLogger(__name__)

import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'onnxconverter_common' is not used.
import onnxscript
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'make_model_ex' is not used.
from onnxscript import optimizer, ir
import onnxconverter_common
from onnxconverter_common.onnx_ex import make_model_ex
import onnxruntime as rt

Check notice

Code scanning / CodeQL

Unused import Note

Import of 'rt' is not used.
Comment on lines +315 to +316
# if func_infer_shape is not None:
# model = func_infer_shape(model)

Check notice

Code scanning / CodeQL

Commented-out code Note

This comment appears to contain commented-out code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants