huggingface / huggingface/optimum-executorch
Model load errors suppressed, leading to UnboundLocalError
- Dominant language
- Python
- Stars
- 141
- Forks
- 48
- Avg merge
- 26m
- Merged PRs (30d)
- 2
Description
When the `_load_eager_pretrained` call fails in [optimum/exporters/executorch/tasks/causal_lm.py](https://github.com/huggingface/optimum-executorch/blob/370077a59ca542a9dc6e68a07eeb11343b9b0936/optimum/exporters/executorch/tasks/causal_lm.py#L104), the error is caught. There is some logic to handle SDPA errors (see below), but if the error doesn't match this, it is silently dropped. The program continues forward and hits an UnboundLocalError when trying to access the loaded model. This hides the actual error, which gives useful information.
https://github.com/huggingface/optimum-executorch/blob/370077a59ca542a9dc6e68a07eeb11343b9b0936/optimum/exporters/executorch/tasks/causal_lm.py#L114-L127
Example error:
```
Traceback (most recent call last):
File "/home/gjcomer/.conda/envs/et-rc3/bin/optimum-cli", line 7, in
sys.exit(main())
^^^^^^
File "/home/gjcomer/.conda/envs/et-rc3/lib/python3.12/site-packages/optimum/commands/optimum_cli.py", line 208, in main
service.run()
File "/home/gjcomer/.conda/envs/et-rc3/lib/python3.12/site-packages/optimum/commands/export/executorch.py", line 181, in run
main_export(
File "/home/gjcomer/.conda/envs/et-rc3/lib/python3.12/site-packages/optimum/exporters/executorch/__main__.py", line 138, in main_export
model = task_func(model_name_or_path, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/gjcomer/.conda/envs/et-rc3/lib/python3.12/site-packages/optimum/exporters/executorch/tasks/causal_lm.py", line 131, in load_causal_lm_model
for param in eager_model.parameters():
^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'eager_model' where it is not associated with a value
```
In this case, updating the optimum-executorch code to propagate the underlying exception showed the real error:
```
ValueError: Unrecognized configuration class for this kind of AutoModel: AutoModelForCausalLM.
```
## Suggested Resolution
Re-throw or display the error in the except block above.
Contributor guide
Assessment
This issue has not been assessed yet.