UnboundLocalError: cannot access local variable 'all_files' where it is not associated with a value

D:\Users\Administrator>optimum-cli export onnx --model bert-base-uncased bert_base_uncased_onnx
Traceback (most recent call last):
File “”, line 198, in run_module_as_main
File “”, line 88, in run_code
File "E:\ProgramData\anaconda3\envs\HF\Scripts\optimum-cli.exe_main
.py", line 7, in
File “E:\ProgramData\anaconda3\envs\HF\Lib\site-packages\optimum\commands\optimum_cli.py”, line 163, in main
service.run()
File “E:\ProgramData\anaconda3\envs\HF\Lib\site-packages\optimum\commands\export\onnx.py”, line 219, in run
main_export(
File "E:\ProgramData\anaconda3\envs\HF\Lib\site-packages\optimum\exporters\onnx_main
.py", line 171, in main_export
framework = TasksManager.determine_framework(model_name_or_path, subfolder=subfolder, framework=framework)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “E:\ProgramData\anaconda3\envs\HF\Lib\site-packages\optimum\exporters\tasks.py”, line 1207, in determine_framework
for file in all_files
^^^^^^^^^
UnboundLocalError: cannot access local variable ‘all_files’ where it is not associated with a value

@Erye The name of the output folder should be the last argument of the command, it is missing here. It should work with:

optimum-cli export onnx --model bert-base-uncased onnx_model

What is the version of Optimum you are using? With the latest release, you should get an error message such as this one:

optimum-cli export onnx: error: the following arguments are required: output

I’m currently stuck with the same issue.
I’m running the following command
optimum-cli export onnx -m my-Model-name.pth out

File “c:\users\myUser\appdata\local\programs\python\python38\lib\site-packages\optimum\exporters\tasks.py”, line 1261, in get_model_files
return all_files, request_exception
UnboundLocalError: local variable ‘all_files’ referenced before assignment

Used version:
optimum==1.14.0

Do you know what I’m missing?

Hi @Anyeahh! Could you try again replacing my-Model-name.pth by the name of the folder it is located in please?

Xu Yao Ti Zi (Fan Qiang)