Commit ac92781
committed
[ez] Fix idx in duplicate_constant_node_pass
Summary:
## Context
Prevent errors like
```
Export failed with error: Command '['optimum-cli', 'export', 'executorch', '--model', 'NousResearch/Llama-3.2-1B', '--task', 'text-generation', '--recipe', 'vulkan', '--output_dir', '/var/folders/ch/wpn5l1rx3p17k4r6w3mhsdgr0000gn/T/tmp7zzmlks6']' returned non-zero exit status 2.
test_fn(
File "/Users/ssjia/scratch/scripts/test_hf_model.py", line 74, in test_text_generation
model = ExecuTorchModelForCausalLM.from_pretrained(model_id, recipe=recipe)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/executorch/modeling.py", line 341, in from_pretrained
models_dict = cls._export(
^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/executorch/modeling.py", line 249, in _export
executorch_progs = main_export(
^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/exporters/executorch/__main__.py", line 140, in main_export
return export_to_executorch(
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/exporters/executorch/convert.py", line 83, in export_to_executorch
executorch_progs = recipe_func(model, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/exporters/executorch/recipes/vulkan.py", line 123, in export_to_executorch_with_vulkan
return _lower_to_executorch(exported_progs, model.metadata)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/optimum-executorch/optimum/exporters/executorch/recipes/vulkan.py", line 80, in _lower_to_executorch
et_progs[pte_name] = to_edge_transform_and_lower(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/executorch/src/executorch/exir/program/_program.py", line 113, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/executorch/src/executorch/exir/program/_program.py", line 1342, in to_edge_transform_and_lower
edge_manager = edge_manager.to_backend(method_to_partitioner)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/executorch/src/executorch/exir/program/_program.py", line 113, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/executorch/src/executorch/exir/program/_program.py", line 1643, in to_backend
new_edge_programs = to_backend(method_to_programs_and_partitioners)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/fbcode/platform010/Python3.12.framework/Versions/3.12/lib/python3.12/functools.py", line 912, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ssjia/Github/executorch/src/executorch/exir/backend/backend_api.py", line 732, in _
_maybe_duplicate_constant_nodes(tagged_exported_program, tag)
File "/Users/ssjia/Github/executorch/src/executorch/exir/backend/utils.py", line 244, in _maybe_duplicate_constant_nodes
duplicate_constant_node(tagged_exported_program, candidate_node)
File "/Users/ssjia/Github/executorch/src/executorch/exir/backend/canonical_partitioners/duplicate_constant_node_pass.py", line 67, in duplicate_constant_node
old_input_spec = old_signature.input_specs[idx]
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^
IndexError: list index out of range
```
This happens when there are non-placeholder nodes that appear before the last placeholder nodes in `exported_program.graph.nodes`; in this case the pass will try to access an input spec outside the bounds of the graph signature.
## Fix
Instead of tracking the index of the the current node being processed, track the number of placeholder nodes observed. This will ensure that the input spec being accessed will match the current placeholder node being processed.
[ghstack-poisoned]1 parent 2c0752a commit ac92781
File tree
1 file changed
+6
-2
lines changed- exir/backend/canonical_partitioners
1 file changed
+6
-2
lines changedLines changed: 6 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
68 | 72 | | |
69 | 73 | | |
70 | 74 | | |
| |||
0 commit comments