golemfactory / ya-runtime-ai

1 stars 1 forks source link

Reject models other than `safetensor` #106

Open pwalski opened 2 months ago

pwalski commented 2 months ago

Verify if model is safetensor kind of model. Reject it if it is not.

scresh commented 2 weeks ago

Automatic1111 validates the file format itself (based on file extension). If one tries to pass ckpt model with .safetensors extension, then Automatic1111 will throw the following error:

2024-06-19T06:28:22.452592577Z reading metadata for /usr/src/app/output/models/undercover_ckpt.safetensors: AssertionError
2024-06-19T06:28:22.452622746Z Traceback (most recent call last):
2024-06-19T06:28:22.452625796Z   File "/usr/src/app/stable-diffusion-webui/modules/sd_models.py", line 75, in __init__
2024-06-19T06:28:22.452628236Z     self.metadata = cache.cached_data_for_file('safetensors-metadata', "checkpoint/" + name, filename, read_metadata)
2024-06-19T06:28:22.452630056Z   File "/usr/src/app/stable-diffusion-webui/modules/cache.py", line 115, in cached_data_for_file
2024-06-19T06:28:22.452631866Z     value = func()
2024-06-19T06:28:22.452633966Z   File "/usr/src/app/stable-diffusion-webui/modules/sd_models.py", line 67, in read_metadata
2024-06-19T06:28:22.452637906Z     metadata = read_metadata_from_safetensors(filename)
2024-06-19T06:28:22.452640166Z   File "/usr/src/app/stable-diffusion-webui/modules/sd_models.py", line 282, in read_metadata_from_safetensors
2024-06-19T06:28:22.452652996Z     assert metadata_len > 2 and json_start in (b'{"', b"{'"), f"{filename} is not a safetensors file"
2024-06-19T06:28:22.452654946Z AssertionError: /usr/src/app/output/models/undercover_ckpt.safetensors is not a safetensors file

Actually we could only check if the given filename ends with .safetensors and let Automatic1111 check if it's valid.