ai-edge-torch-nightly 0.2.0.dev20240620__py3-none-any.whl → 0.2.0.dev20240622__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.
Potentially problematic release.
This version of ai-edge-torch-nightly might be problematic. Click here for more details.
- ai_edge_torch/convert/conversion.py +2 -0
- ai_edge_torch/generative/fx_passes/__init__.py +31 -0
- ai_edge_torch/generative/fx_passes/remove_sdpa_zero_mask_pass.py +47 -0
- {ai_edge_torch_nightly-0.2.0.dev20240620.dist-info → ai_edge_torch_nightly-0.2.0.dev20240622.dist-info}/METADATA +1 -1
- {ai_edge_torch_nightly-0.2.0.dev20240620.dist-info → ai_edge_torch_nightly-0.2.0.dev20240622.dist-info}/RECORD +8 -6
- {ai_edge_torch_nightly-0.2.0.dev20240620.dist-info → ai_edge_torch_nightly-0.2.0.dev20240622.dist-info}/LICENSE +0 -0
- {ai_edge_torch_nightly-0.2.0.dev20240620.dist-info → ai_edge_torch_nightly-0.2.0.dev20240622.dist-info}/WHEEL +0 -0
- {ai_edge_torch_nightly-0.2.0.dev20240620.dist-info → ai_edge_torch_nightly-0.2.0.dev20240622.dist-info}/top_level.txt +0 -0
|
@@ -30,6 +30,7 @@ from ai_edge_torch.convert.fx_passes import CanonicalizePass
|
|
|
30
30
|
from ai_edge_torch.convert.fx_passes import InjectMlirDebuginfoPass
|
|
31
31
|
from ai_edge_torch.convert.fx_passes import OptimizeLayoutTransposesPass
|
|
32
32
|
from ai_edge_torch.convert.fx_passes import run_passes
|
|
33
|
+
from ai_edge_torch.generative.fx_passes import run_generative_passes
|
|
33
34
|
from ai_edge_torch.quantize import quant_config as qcfg
|
|
34
35
|
|
|
35
36
|
os.environ["EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM"] = "1"
|
|
@@ -38,6 +39,7 @@ os.environ["EXPERIMENTAL_XLA_UNBOUNDED_DYNAMISM"] = "1"
|
|
|
38
39
|
def _run_convert_passes(
|
|
39
40
|
exported_program: ExportedProgram,
|
|
40
41
|
) -> ExportedProgram:
|
|
42
|
+
exported_program = run_generative_passes(exported_program)
|
|
41
43
|
return run_passes(
|
|
42
44
|
exported_program,
|
|
43
45
|
[
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Copyright 2024 The AI Edge Torch Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
import torch
|
|
16
|
+
|
|
17
|
+
from ai_edge_torch.convert.fx_passes import CanonicalizePass
|
|
18
|
+
from ai_edge_torch.convert.fx_passes import run_passes
|
|
19
|
+
from ai_edge_torch.generative.fx_passes.remove_sdpa_zero_mask_pass import RemoveSDPACompositeZeroMaskPass # NOQA
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def run_generative_passes(
|
|
23
|
+
exported_program: torch.export.ExportedProgram,
|
|
24
|
+
) -> torch.export.ExportedProgram:
|
|
25
|
+
return run_passes(
|
|
26
|
+
exported_program,
|
|
27
|
+
[
|
|
28
|
+
RemoveSDPACompositeZeroMaskPass(),
|
|
29
|
+
CanonicalizePass(),
|
|
30
|
+
],
|
|
31
|
+
)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright 2024 The AI Edge Torch Authors.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
# ==============================================================================
|
|
15
|
+
import torch
|
|
16
|
+
|
|
17
|
+
from ai_edge_torch.convert.fx_passes._pass_base import ExportedProgramPassBase
|
|
18
|
+
from ai_edge_torch.convert.fx_passes._pass_base import ExportedProgramPassResult # NOQA
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class RemoveSDPACompositeZeroMaskPass(ExportedProgramPassBase):
|
|
22
|
+
|
|
23
|
+
def is_zero_tensor_node(self, node: torch.fx.Node):
|
|
24
|
+
return node.target == torch.ops.aten.zeros.default
|
|
25
|
+
|
|
26
|
+
def call(self, exported_program: torch.export.ExportedProgram):
|
|
27
|
+
graph = exported_program.graph_module.graph
|
|
28
|
+
for node in graph.nodes:
|
|
29
|
+
if not (
|
|
30
|
+
node.op == "call_function"
|
|
31
|
+
and node.target == torch.ops.xla.mark_tensor.default
|
|
32
|
+
):
|
|
33
|
+
continue
|
|
34
|
+
|
|
35
|
+
source, name, io_position, id, is_input = node.args[:5]
|
|
36
|
+
# Composite info:
|
|
37
|
+
# - name: odml.scaled_dot_product_attention
|
|
38
|
+
# - inputs: q, k, v, mask
|
|
39
|
+
if name == "odml.scaled_dot_product_attention" and is_input and io_position == 3:
|
|
40
|
+
if self.is_zero_tensor_node(source):
|
|
41
|
+
# Remove the mark_tensor call on the mask input by
|
|
42
|
+
# replacing the target with an identity function.
|
|
43
|
+
node.target = lambda *args, **kwargs: args[0]
|
|
44
|
+
|
|
45
|
+
exported_program.graph_module.graph.lint()
|
|
46
|
+
exported_program.graph_module.recompile()
|
|
47
|
+
return ExportedProgramPassResult(exported_program, True)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: ai-edge-torch-nightly
|
|
3
|
-
Version: 0.2.0.
|
|
3
|
+
Version: 0.2.0.dev20240622
|
|
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
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
ai_edge_torch/__init__.py,sha256=FPMmuFU3pyMREtjB_san1fy_0PFtAsgA0VZfOYvDrb4,1008
|
|
2
2
|
ai_edge_torch/model.py,sha256=kmcgELjsYl8YzF8nUF6P7q4i8MWS-pLGpfsy-yTUXmE,4243
|
|
3
3
|
ai_edge_torch/convert/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
|
|
4
|
-
ai_edge_torch/convert/conversion.py,sha256=
|
|
4
|
+
ai_edge_torch/convert/conversion.py,sha256=8K8jQuaCjlUWoj7jiimxp_zpN6mYThLOcQ858UDcYnE,4159
|
|
5
5
|
ai_edge_torch/convert/conversion_utils.py,sha256=9BqCL38DErv1vEVGtT3BIJVhdwZjw2EQ-_m5UpvVVYE,11294
|
|
6
6
|
ai_edge_torch/convert/converter.py,sha256=bjj5TV5_g4sGyuSh8ThEDydlNMqhkGSY4SzXK6vwhqI,6927
|
|
7
7
|
ai_edge_torch/convert/fx_passes/__init__.py,sha256=EPs4PSIDLuRH5EBETi6deaOvaaf_Q4xD3_9NVcR7x8o,2810
|
|
@@ -65,6 +65,8 @@ ai_edge_torch/generative/examples/test_models/toy_model_with_kv_cache.py,sha256=
|
|
|
65
65
|
ai_edge_torch/generative/examples/tiny_llama/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
66
|
ai_edge_torch/generative/examples/tiny_llama/convert_to_tflite.py,sha256=E4I5OlC4zyl5cxiiu7uTED-zcwYRu210lP1zuT3xLBE,2566
|
|
67
67
|
ai_edge_torch/generative/examples/tiny_llama/tiny_llama.py,sha256=IFRLPG9wz_aLl_zV_6CETCjSM03ukA6bZqqyDLVACuw,5651
|
|
68
|
+
ai_edge_torch/generative/fx_passes/__init__.py,sha256=aXvYiaHDvETIrh0Q9DDZA_ZBiazGk80DT6nt7lLtC1o,1172
|
|
69
|
+
ai_edge_torch/generative/fx_passes/remove_sdpa_zero_mask_pass.py,sha256=IehLwFNwa0C9fnk1pmNmyfuAwwWbuwdyKy46BSqNVdI,1948
|
|
68
70
|
ai_edge_torch/generative/layers/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
|
|
69
71
|
ai_edge_torch/generative/layers/attention.py,sha256=AW0Qo3uOIe6p1rJNJ6zR_r4fqL2y-6QJHh0yUd-5Yb0,11966
|
|
70
72
|
ai_edge_torch/generative/layers/attention_utils.py,sha256=hXhuyKblPPxKIRzlAf1YNlwHgpbj-6nReRLhRHELx5k,6350
|
|
@@ -110,8 +112,8 @@ ai_edge_torch/quantize/quant_config.py,sha256=eO9Ra160ITjQSyRBEGy6nNIVH3gYacSWDd
|
|
|
110
112
|
ai_edge_torch/testing/__init__.py,sha256=hHLluseD2R0Hh4W6XZRIXY_dRQeYudjsrKGf6LZz65g,671
|
|
111
113
|
ai_edge_torch/testing/model_coverage/__init__.py,sha256=5P8J6Zk5YYtDvTBucFvB9NGSRI7Gw_24WnrbhXgycEE,765
|
|
112
114
|
ai_edge_torch/testing/model_coverage/model_coverage.py,sha256=EIyKz-HY70DguWuSrJal8LpYXQ5ZSEUf3ZrVl7jikFM,4286
|
|
113
|
-
ai_edge_torch_nightly-0.2.0.
|
|
114
|
-
ai_edge_torch_nightly-0.2.0.
|
|
115
|
-
ai_edge_torch_nightly-0.2.0.
|
|
116
|
-
ai_edge_torch_nightly-0.2.0.
|
|
117
|
-
ai_edge_torch_nightly-0.2.0.
|
|
115
|
+
ai_edge_torch_nightly-0.2.0.dev20240622.dist-info/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
116
|
+
ai_edge_torch_nightly-0.2.0.dev20240622.dist-info/METADATA,sha256=6lsbM34bqpsvW83B8kORnV885PDPT8HXFKfaIcMHLzA,1748
|
|
117
|
+
ai_edge_torch_nightly-0.2.0.dev20240622.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
118
|
+
ai_edge_torch_nightly-0.2.0.dev20240622.dist-info/top_level.txt,sha256=5KXRaF2hwkApYxf7Y8y_tVb9aulGTlbOoNdbx1aKRkE,14
|
|
119
|
+
ai_edge_torch_nightly-0.2.0.dev20240622.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|