| 925 | if is_torch_available(): |
| 926 | # Update device function dict mapping |
| 927 | def update_mapping_from_spec(device_fn_dict: Dict[str, Callable], attribute_name: str): |
| 928 | try: |
| 929 | # Try to import the function directly |
| 930 | spec_fn = getattr(device_spec_module, attribute_name) |
| 931 | device_fn_dict[torch_device] = spec_fn |
| 932 | except AttributeError as e: |
| 933 | # If the function doesn't exist, and there is no default, throw an error |
| 934 | if "default" not in device_fn_dict: |
| 935 | raise AttributeError( |
| 936 | f"`{attribute_name}` not found in '{device_spec_path}' and no default fallback function found." |
| 937 | ) from e |
| 938 | |
| 939 | if "DIFFUSERS_TEST_DEVICE_SPEC" in os.environ: |
| 940 | device_spec_path = os.environ["DIFFUSERS_TEST_DEVICE_SPEC"] |