kijai / ComfyUI-KJNodes

Various custom nodes for ComfyUI
GNU General Public License v3.0
649 stars 76 forks source link

Superprompt first time setup HFValidationError: Local Model Path Fails Repo ID Validation in from_pretrained #82

Open Shadetail opened 5 months ago

Shadetail commented 5 months ago

Got this error on my first ever attempt to run the Superprompt node:

[rgthree] Using rgthree's optimized recursive execution.
tokenizer_config.json: 100%|██████████████████████████████████████████████████████| 2.54k/2.54k [00:00<00:00, 2.54MB/s]
spiece.model: 100%|█████████████████████████████████████████████████████████████████| 792k/792k [00:00<00:00, 56.9MB/s]
special_tokens_map.json: 100%|████████████████████████████████████████████████████████████| 2.20k/2.20k [00:00<?, ?B/s]
tokenizer.json: 100%|█████████████████████████████████████████████████████████████| 2.42M/2.42M [00:00<00:00, 7.45MB/s]
Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.
!!! Exception during processing!!! Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-KJNodes\models\superprompt-v1'.
Traceback (most recent call last):
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\execution.py", line 151, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\execution.py", line 81, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\execution.py", line 74, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-KJNodes\nodes\nodes.py", line 1336, in process
    model = T5ForConditionalGeneration.from_pretrained(checkpoint_path, device_map=device)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\python_embeded\Lib\site-packages\transformers\modeling_utils.py", line 2600, in from_pretrained
    resolved_config_file = cached_file(
                           ^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\python_embeded\Lib\site-packages\transformers\utils\hub.py", line 430, in cached_file
    resolved_file = hf_hub_download(
                    ^^^^^^^^^^^^^^^^
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\python_embeded\Lib\site-packages\huggingface_hub\utils\_validators.py", line 110, in _inner_fn
    validate_repo_id(arg_value)
  File "C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\python_embeded\Lib\site-packages\huggingface_hub\utils\_validators.py", line 164, in validate_repo_id
    raise HFValidationError(
huggingface_hub.utils._validators.HFValidationError: Repo id must use alphanumeric chars or '-', '_', '.', '--' and '..' are forbidden, '-' and '.' cannot start or end the name, max length is 96: 'C:\Users\Mario\Documents\GitHub\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-KJNodes\models\superprompt-v1'.

Prompt executed in 2.05 seconds

In case it's useful, here's GPT4 analysis, no idea if it's correct:

The error you're encountering arises from an invalid repository ID being passed to the from_pretrained method, which is intended to load models from the Hugging Face Hub, not from local file paths. The repository ID validation fails because it does not meet the naming conventions required by Hugging Face, and local file paths are not acceptable inputs for this method.

To fix this issue, if you're trying to load a model from a local directory, use the correct method for local loading. Here's how you can adjust your code:

Instead of:

model = T5ForConditionalGeneration.from_pretrained(checkpoint_path, device_map=device) Use:

model = T5ForConditionalGeneration.from_pretrained('path/to/your/local/model/directory') Ensure that the path/to/your/local/model/directory is the correct local path where your model and its configuration file are stored. This should bypass the repository ID validation and load the model from your specified local directory.

Shadetail commented 5 months ago

I worked around this issue by manually cloning the superprompt huggingface repository into this folder: ...\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-KJNodes\models

To do that, just open that folder, type cmd into the explorer address bar, press enter to open command prompt in that current folder, then paste this: git clone https://huggingface.co/roborovski/superprompt-v1.git superprompt-v1

After restarting comfyui, the superprompt node now works!

I'm leaving the issue open, as the issue is about this not working automatically, as I expect that it should. And if it's not intended to work automatically, then the error should be changed to be an instruction of what needs to be done.

kijai commented 5 months ago

Yeah it didn't have autodownload, when I first implemented it that hugginface repo didn't allow for it, seems to work now so I added it.