ai-edge-torch-nightly 0.4.0.dev20250224__py3-none-any.whl → 0.4.0.dev20250226__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -125,6 +125,10 @@ def convert_signatures(
125
125
  else:
126
126
  exported_program = torch.export.export(**kwargs, strict=True)
127
127
 
128
+ exported_program = fx_infra.graph_utils.reset_from_node_meta(
129
+ exported_program
130
+ )
131
+
128
132
  exported_program = fx_infra.safe_run_decompositions(
129
133
  exported_program,
130
134
  fx_infra.decomp.pre_convert_decomp(),
@@ -13,7 +13,10 @@
13
13
  # limitations under the License.
14
14
  # ==============================================================================
15
15
  """FX graph utilities."""
16
+
17
+ from packaging import version
16
18
  import torch
19
+ from torch.fx import traceback
17
20
 
18
21
 
19
22
  def remove_dangling_args(graph_module: torch.fx.GraphModule):
@@ -40,3 +43,32 @@ def remove_assert_tensor_metadata_nodes(graph_module: torch.fx.GraphModule):
40
43
  graph_module.graph.lint()
41
44
  graph_module.recompile()
42
45
  return graph_module
46
+
47
+
48
+ def is_torch_version_under(torch_version: str) -> bool:
49
+ """Checks if the current torch version is under the given version."""
50
+ if not torch_version:
51
+ raise ValueError("torch_version cannot be empty.")
52
+ current_version = version.parse(torch.__version__)
53
+ compared_version = version.parse(torch_version)
54
+ return current_version < compared_version
55
+
56
+
57
+ def reset_from_node_meta(ep: torch.export.ExportedProgram):
58
+ """Resets the "from_node" meta field to fx node name only for the exported program."""
59
+
60
+ for node in ep.graph.nodes:
61
+ if not hasattr(node, "meta") or "from_node" not in node.meta:
62
+ continue
63
+ if is_torch_version_under("2.6.0.dev0"):
64
+ # For torch version under 2.6.0, the history stack is a list of tuple. We
65
+ # will only keep the current node's name in the history stack.
66
+ history = [(node.name,)]
67
+ else:
68
+ # Clean up the history stack by keeping only the current node info (fx
69
+ # node name and graph id) in a list of size 1. Clear the "from_node" field
70
+ # to prevent redundant additions to the history stack.
71
+ history = [traceback.NodeSource(node)]
72
+ history[0].from_node = []
73
+ node.meta["from_node"] = history
74
+ return ep
@@ -13,6 +13,7 @@
13
13
  # limitations under the License.
14
14
  # ==============================================================================
15
15
  import re
16
+ from ai_edge_torch.fx_infra import graph_utils
16
17
  import torch
17
18
 
18
19
 
@@ -48,8 +49,6 @@ def _get_canonical_filename(filename: str):
48
49
  The canonicalized filename.
49
50
  """
50
51
 
51
- # TODO(yijieyang): We should add a config option to provide a regex to strip
52
- # from the debug info. Currently absolute path is used.
53
52
  return filename
54
53
 
55
54
 
@@ -57,9 +56,13 @@ def _get_canoical_nodename(node: torch.fx.Node) -> str:
57
56
  """Get the canonical node name from the node's history."""
58
57
 
59
58
  history = node.meta.get("from_node", [])
59
+ if not history:
60
+ return None
60
61
 
61
- if len(history) > 1: # Compatible with torch version under 2.6.0
62
- return history[1][0]
62
+ # Compatible with torch version under 2.6.0. The history stack is a list of
63
+ # tuple. The first element of the first tuple is the node name.
64
+ if graph_utils.is_torch_version_under("2.6.0.dev0"):
65
+ return history[0][0]
63
66
 
64
67
  if not hasattr(history[0], "name"):
65
68
  return None
@@ -68,12 +71,10 @@ def _get_canoical_nodename(node: torch.fx.Node) -> str:
68
71
  names.append(history[0].name)
69
72
  history = history[0].from_node
70
73
 
71
- # Based on the experiment, the third to last name in the history stack
72
- # can be mapped to the original torch node name. The history stack is
73
- # generated by tracing the node's transformation history during lowering.
74
- if len(names) > 2:
75
- return names[-3]
76
- return None
74
+ # The history stack is generated by tracing the node's transformation history
75
+ # during lowering. The last name in the history stack is used to map to the
76
+ # original torch fx node name.
77
+ return names[-1]
77
78
 
78
79
 
79
80
  def build_mlir_file_debuginfo(node: torch.fx.Node):
ai_edge_torch/version.py CHANGED
@@ -13,4 +13,4 @@
13
13
  # limitations under the License.
14
14
  # ==============================================================================
15
15
 
16
- __version__ = "0.4.0.dev20250224"
16
+ __version__ = "0.4.0.dev20250226"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ai-edge-torch-nightly
3
- Version: 0.4.0.dev20250224
3
+ Version: 0.4.0.dev20250226
4
4
  Summary: Supporting PyTorch models with the Google AI Edge TFLite runtime.
5
5
  Home-page: https://github.com/google-ai-edge/ai-edge-torch
6
6
  Keywords: On-Device ML,AI,Google,TFLite,PyTorch,LLMs,GenAI
@@ -2,9 +2,9 @@ ai_edge_torch/__init__.py,sha256=8sPR_5uXJA4NEE0nIwNdSl-ADOJEoR8hAgYvBQDY70Y,120
2
2
  ai_edge_torch/_config.py,sha256=AiqhbcheF7j_ozIGDLC89k1we95aVgFDa-tR6h7UI0s,2529
3
3
  ai_edge_torch/conftest.py,sha256=r0GTrhMRhlmOGrrkvumHN8hkmyug6WvF60vWq8wRIBI,758
4
4
  ai_edge_torch/model.py,sha256=N-pNpTxzhaFGhWhnSGd70lBzb9VlEhTOq5mddU7bvvI,5542
5
- ai_edge_torch/version.py,sha256=Ga5ZnqgXb2idvQhACflPLWvlRmVZQ38CA2KtcWsGEKU,706
5
+ ai_edge_torch/version.py,sha256=Redqgp3EjtlXSINPZlLb-pjbUH61Ie1ejPLMQ8bl_lE,706
6
6
  ai_edge_torch/_convert/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
7
- ai_edge_torch/_convert/conversion.py,sha256=mckvxznKLXdF2HuJg_IxQaT5Ty-iWl_iXElHEugH3VI,5452
7
+ ai_edge_torch/_convert/conversion.py,sha256=gpXQnifODU-mWxkUZw_3ov1lEYBw1SPVIcqj5k7pTGo,5550
8
8
  ai_edge_torch/_convert/conversion_utils.py,sha256=Sr8qXVcTwc-ZnZmK7yxVrIOOp1S_vNrwzC0zUvLTI2o,2160
9
9
  ai_edge_torch/_convert/converter.py,sha256=075F8LRewk_033Ebsnft7FJr3KgtIbtZ_-8udIPy6ho,9980
10
10
  ai_edge_torch/_convert/signature.py,sha256=-YKJdLk-eNEHfhdPCtcQVtZf915SoVePEFxKXPPf16c,2572
@@ -41,7 +41,7 @@ ai_edge_torch/fx_infra/__init__.py,sha256=APjkSqEfwDxcnI8k53rGi3Ef-G2L-M8fdaPGpx
41
41
  ai_edge_torch/fx_infra/_canonicalize_pass.py,sha256=GDRoDdPVQw--QQFTT5J_C3TVuphL31m6K6F1-67SE4s,1097
42
42
  ai_edge_torch/fx_infra/_safe_run_decompositions.py,sha256=ZbWheeZ8ydsxCk2aVGUgUynrkEkBOMjBCzPhS5uq4sU,2595
43
43
  ai_edge_torch/fx_infra/decomp.py,sha256=S58SCgwMHYVFl_hJwlJxvu2wcI-AGNn82gel3qmTPrU,2500
44
- ai_edge_torch/fx_infra/graph_utils.py,sha256=3UZAOHWOUh2LCj1E2_AKQn3gRDILi9JCdqSScjyOd4M,1535
44
+ ai_edge_torch/fx_infra/graph_utils.py,sha256=nqGe-xIJ77RamSUh0UYyI2XHOsZqFDWax-vpRAtVR_E,2796
45
45
  ai_edge_torch/fx_infra/pass_base.py,sha256=Ic2AlhSoRFscz6l7gJKvWVNMDLQFfAw5kRf84-ZR9qM,2904
46
46
  ai_edge_torch/generative/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
47
47
  ai_edge_torch/generative/examples/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
@@ -205,7 +205,7 @@ ai_edge_torch/odml_torch/composite/__init__.py,sha256=71GM_gDZxJyo38ZSoYSwhZX3xK
205
205
  ai_edge_torch/odml_torch/composite/mark_tensor.py,sha256=U--rwl-XkWKgkdXCXDn6yySug8FR66o1YFUAIoSaWW4,3523
206
206
  ai_edge_torch/odml_torch/composite/stablehlo_composite_builder.py,sha256=2Y52E_gLeoXpMcPpV-svXsgN3JbEIjnPVjm0xkpTUdQ,3319
207
207
  ai_edge_torch/odml_torch/debuginfo/__init__.py,sha256=3A_lMyj-B-DOhLJG6WmjKvZK5te2rXje8FrfqOhZsN0,959
208
- ai_edge_torch/odml_torch/debuginfo/_build.py,sha256=k9Kas790kpMS5OrVcLzIr48ejAzcc2smrroKAHHM7TQ,3311
208
+ ai_edge_torch/odml_torch/debuginfo/_build.py,sha256=6Ns2rlfOilLJEk5cUxlkRwm2uxOgEF2-0S2DMcOqr6A,3319
209
209
  ai_edge_torch/odml_torch/debuginfo/_op_polyfill.py,sha256=IvOBQyROI9WHS3umHRxsDW-1YElU9BPWzKtJA2eKWOI,1739
210
210
  ai_edge_torch/odml_torch/jax_bridge/__init__.py,sha256=e9Oa4J3An9FYr3zM0OzjzyNNitEeg-IoBUGNfUxsDSA,798
211
211
  ai_edge_torch/odml_torch/jax_bridge/_wrap.py,sha256=LqwZ1vCJTSOzgzvH8LUAN-sAkF-l_pGj1AMEIzAqHCA,6638
@@ -230,8 +230,8 @@ ai_edge_torch/quantize/quant_config.py,sha256=U0KisSW-uZkoMJcy-ZP9W57p3tsa594fr9
230
230
  ai_edge_torch/testing/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
231
231
  ai_edge_torch/testing/model_coverage/__init__.py,sha256=5P8J6Zk5YYtDvTBucFvB9NGSRI7Gw_24WnrbhXgycEE,765
232
232
  ai_edge_torch/testing/model_coverage/model_coverage.py,sha256=UPB448aMDUyC0HNYVqio2rcJPnDN0tBQMP08J6vPYew,4718
233
- ai_edge_torch_nightly-0.4.0.dev20250224.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
234
- ai_edge_torch_nightly-0.4.0.dev20250224.dist-info/METADATA,sha256=K_9APQQGmsQkmF3tdAhAnLvwHAdFdkvlotoJ2KzrEvA,1966
235
- ai_edge_torch_nightly-0.4.0.dev20250224.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
236
- ai_edge_torch_nightly-0.4.0.dev20250224.dist-info/top_level.txt,sha256=5KXRaF2hwkApYxf7Y8y_tVb9aulGTlbOoNdbx1aKRkE,14
237
- ai_edge_torch_nightly-0.4.0.dev20250224.dist-info/RECORD,,
233
+ ai_edge_torch_nightly-0.4.0.dev20250226.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
234
+ ai_edge_torch_nightly-0.4.0.dev20250226.dist-info/METADATA,sha256=N6T5-MKa5Ztwx_XE7OJ8wiw2BC00e0dQxgngvI9S6CU,1966
235
+ ai_edge_torch_nightly-0.4.0.dev20250226.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
236
+ ai_edge_torch_nightly-0.4.0.dev20250226.dist-info/top_level.txt,sha256=5KXRaF2hwkApYxf7Y8y_tVb9aulGTlbOoNdbx1aKRkE,14
237
+ ai_edge_torch_nightly-0.4.0.dev20250226.dist-info/RECORD,,