You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The expected behavior is that it creates a file src/transformers/models/xxx_model/image_processing_xxx.py. However, the script fails with the following traceback:
Traceback (most recent call last):
File "/Users/houxiuquan/Downloads/transformers/utils/modular_model_converter.py", line 1726, in<module>
converted_files = convert_modular_file(file_name)
File "/Users/houxiuquan/Downloads/transformers/utils/modular_model_converter.py", line 1663, in convert_modular_file
forfile, moduleincreate_modules(cst_transformers).items():
File "/Users/houxiuquan/Downloads/transformers/utils/modular_model_converter.py", line 1643, in create_modules
needed_imports = get_needed_imports(body, all_imports)
File "/Users/houxiuquan/Downloads/transformers/utils/modular_model_converter.py", line 1151, in get_needed_imports
append_new_import_node(stmt_node, unused_imports, added_names, new_statements)
File "/Users/houxiuquan/Downloads/transformers/utils/modular_model_converter.py", line 1111, in append_new_import_node
fornamein import_node.names:
AttributeError: 'Return' object has no attribute 'names'
I found the error is caused by the local imports with return in the following function of transformer.models.detr.image_processing_detr:
defget_numpy_to_framework_fn(arr) ->Callable:
""" Returns a function that converts a numpy array to the framework of the input array. Args: arr (`np.ndarray`): The array to convert. """ifisinstance(arr, np.ndarray):
returnnp.arrayifis_tf_available() andis_tf_tensor(arr):
importtensorflowastfreturntf.convert_to_tensorifis_torch_available() andis_torch_tensor(arr):
importtorchreturntorch.tensorifis_flax_available() andis_jax_tensor(arr):
importjax.numpyasjnpreturnjnp.arrayraiseValueError(f"Cannot convert arrays of type {type(arr)}")
When removing the return row, the script works:
defget_numpy_to_framework_fn(arr) ->Callable:
""" Returns a function that converts a numpy array to the framework of the input array. Args: arr (`np.ndarray`): The array to convert. """ifisinstance(arr, np.ndarray):
returnnp.arrayifis_tf_available() andis_tf_tensor(arr):
importtensorflowastf# return tf.convert_to_tensorifis_torch_available() andis_torch_tensor(arr):
importtorch# return torch.tensorifis_flax_available() andis_jax_tensor(arr):
importjax.numpyasjnp# return jnp.arrayraiseValueError(f"Cannot convert arrays of type {type(arr)}")
If moving the import outside the function (global import), the script also works:
importtensorflowastfimporttorchimportjax.numpyasjnpdefget_numpy_to_framework_fn(arr) ->Callable:
""" Returns a function that converts a numpy array to the framework of the input array. Args: arr (`np.ndarray`): The array to convert. """ifisinstance(arr, np.ndarray):
returnnp.arrayifis_tf_available() andis_tf_tensor(arr):
returntf.convert_to_tensorifis_torch_available() andis_torch_tensor(arr):
returntorch.tensorifis_flax_available() andis_jax_tensor(arr):
returnjnp.arrayraiseValueError(f"Cannot convert arrays of type {type(arr)}")
The text was updated successfully, but these errors were encountered:
System Info
transformers
version: 4.49.0.dev0Who can help?
No response
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
xxx_model
insrc/transformers/models/
modular_xxx.py
with the following content:Expected behavior
The expected behavior is that it creates a file
src/transformers/models/xxx_model/image_processing_xxx.py
. However, the script fails with the following traceback:I found the error is caused by the local imports with
return
in the following function oftransformer.models.detr.image_processing_detr
:When removing the
return
row, the script works:If moving the import outside the function (global import), the script also works:
The text was updated successfully, but these errors were encountered: