Skip to content

Commit c0e688b

Browse files
authored
[torch-frontend] use min(target_version, current_version) as target_v… (#460)
…ersion
1 parent 5b9a49e commit c0e688b

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

frontends/torch-frontend/torch-frontend/python/test/test_stablehlo_bytecode.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ def serialize_helper(module, inputs):
99
stablehlo_bytecode = compile(module, inputs, "stablehlo+0.16.2")
1010
deserialize_str = deserialize_portable_artifact(stablehlo_bytecode)
1111
print(deserialize_str)
12+
stablehlo_bytecode = compile(module, inputs, "stablehlo+10.0.0")
13+
deserialize_str = deserialize_portable_artifact(stablehlo_bytecode)
14+
print(deserialize_str)
1215

1316
# ==============================================================================
1417
class SoftmaxModule(torch.nn.Module):

frontends/torch-frontend/torch-frontend/python/torch_frontend/compile.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from . import ir
1313
from .passmanager import PassManager
14-
from ._mlir_libs._stablehlo import serialize_portable_artifact
14+
from ._mlir_libs._stablehlo import serialize_portable_artifact, get_current_version
1515

1616
from .extra_shape_fn import byteir_extra_library
1717

@@ -259,8 +259,13 @@ def compile(
259259
############################################
260260
# serialize stablehlo to target version
261261
############################################
262+
from packaging import version
263+
target_version = version.Version(output_type.split("+")[1])
264+
current_version = version.Version(get_current_version())
265+
if target_version > current_version:
266+
target_version = current_version
262267
return serialize_portable_artifact(
263-
module.operation.get_asm(), output_type.split("+")[1]
268+
module.operation.get_asm(), str(target_version)
264269
)
265270

266271

@@ -380,6 +385,11 @@ def compile_dynamo_model(
380385
############################################
381386
# serialize stablehlo to target version
382387
############################################
388+
from packaging import version
389+
target_version = version.Version(output_type.split("+")[1])
390+
current_version = version.Version(get_current_version())
391+
if target_version > current_version:
392+
target_version = current_version
383393
return serialize_portable_artifact(
384-
module.operation.get_asm(), output_type.split("+")[1]
394+
module.operation.get_asm(), str(target_version)
385395
)

0 commit comments

Comments
 (0)