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

[ORTModule] Symbolic Shape Support for Triton Codegen #18317

Merged
merged 5 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix lint
  • Loading branch information
centwang committed Nov 7, 2023
commit 7e0f97dc81d0b65567ae24d6f881bdacf550afe7
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def ModuleNode(self, node: ModuleNode, context: CodegenContext, code_buffer: Cod
for input in node.inputs:
for idx, dim in enumerate(input.shape):
if dim.is_symbol and dim not in seen_symbolic_shape:
code_buffer += f"{space_indent}{str(dim)} = {context.get_variable_name(input.name)}.size()[{idx}]\n"
code_buffer += f"{space_indent}{dim} = {context.get_variable_name(input.name)}.size()[{idx}]\n"
seen_symbolic_shape.add(dim)

if node.has_dropout:
Expand Down
6 changes: 3 additions & 3 deletions orttraining/orttraining/python/training/ort_triton/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
from ._sympy_utils import extract_shape_from_symbol
from ._utils import get_attribute, get_reduce_info, next_power_of_2

_SPECIAL_FLOATS: List[str] = ["inf", "-inf"]


class CodegenContext:
"""
record variable name mapping in term of IRnodes.
"""

_special_floats = ["inf", "-inf"]

def __init__(self, var_map: Dict[str, str]):
self._var_map: Dict[str, str] = {**var_map}

Expand All @@ -31,7 +31,7 @@ def get_variable_name(self, name: str) -> str:
def get_internal_variable_name(self, name: str) -> str:
var_name = self._var_map[name]
var_name = self._var_map[var_name] if var_name in self._var_map else var_name
return f'float("{var_name}")' if var_name in self._special_floats else var_name
return f'float("{var_name}")' if var_name in _SPECIAL_FLOATS else var_name


class CodeBuffer:
Expand Down
Loading