Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ui): mm model install error handling #7512

Merged
merged 9 commits into from
Jan 3, 2025

Conversation

psychedelicious
Copy link
Collaborator

Summary

This PR addresses a number of issues with the handling of model install errors:

  • Incorrect links when an install fails due to licence agreement not being accepted. This was an issue for FLUX Control LoRAs.
  • Red error toast with no message. This was caused by a lack of differentiation between the various types model sources.
  • Error messages talking about HF stuff when the model install wasn't from HF.
  • No toast for errors that are not unauthorized or forbidden (e.g. pasted model install URL 404s).
  • Fix some circular import issues to support the above changes by sending more data for model install event payloads.

Other changes in this PR:

  • Minor improvement to the starter models filtering; it now works correctly with base model types.
  • Added a blurb to the config docs for model marketplaces API tokens about how you still need to set your HF token in invokeai.yaml when downloading from HF URLs.

See the commit messages for technical details.

Related Issues / Discussions

QA Instructions

This is a bit tricky to test. We need to test both HF repo ID install sources and "direct" URL install sources, and the 3 types of errors (unauthorized - no API token, forbidden - has API token but didn't agree to TOS, or something else like 404).

The FLUX Canny LoRA is a good test case because it requires the user to agree to BFL's TOS to download:

  • Repo ID: black-forest-labs/FLUX.1-Canny-dev-lora::flux1-canny-dev-lora.safetensors
  • Direct URL: https://huggingface.co/black-forest-labs/FLUX.1-Canny-dev-lora/resolve/main/flux1-canny-dev-lora.safetensors

To test the error types, I needed to create a tester HF account that has an API key but hadn't yet agreed to the BFL agreement for the FLUX Canny LoRA.

When testing a Repo ID, we use the token stored in ~/.cache/huggingface/token. I deleted this file for each test, and entered my token in the MM UI (requires refreshing the browser).

When testing a URL - even a HF URL - we use the token in the remote_api_tokens setting in invokeai.yaml. You need to restart the server if you change this.

I did not test civitai URLs, but it should be exactly the same as HF URLs, because internally it's just using the python requests module or whatever generic network module. The error toasts are also the same for all URLs. HF URLs do not get any special handling.

Expected results

  • HF Repo ID, no token entered in MM UI: error toast directs user to enter your token in the MM UI and try again
  • HF Repo ID, valid token, but didn't agree to TOS: error toast directs user to the repo to agree to the TOS
  • Direct URL that requires a token, but no matching token in invokeai.yaml: error toast directs user to our docs to set up the token in invokeai.yaml
  • Direct URL that requires a token, and has a matching token in invokeai.yaml, but user still got forbidden: error toast directs user to request access from whoever is hosting the model
  • Direct URL that 404's or has any other issue: error toast has a generic "Model Install Error" title and the error message in the description - For example, a 404 has a message of "Not found" if I recall correctly

I got the expected results in my testing.

Merge Plan

n/a

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Documentation added / updated (if applicable)

@github-actions github-actions bot added python PRs that change python files services PRs that change app services frontend PRs that change frontend files docs PRs that change docs python-tests PRs that change python tests labels Jan 3, 2025
This is required to fix an issue with the MM UI's error handling.

Previously, we only included the model source as a string. That could be an arbitrary URL, file path or HF repo id, but the frontend has no parsing logic to differentiate between these different model sources.

Without access to the type of model source, it is difficult to determine how the user should proceed. For example, if it's HF URL with an HTTP unauthorized error, we should direct the user to log in to HF. But if it's a civitai URL with the same error, we should not direct the user to HF.

There are a variety of related edge cases.

With this change, the full `ModelSource` object is included in each model install event, including error events.

I had to fix some circular import issues, hence the import changes to files other than `events_common.py`.
…arately

Previously, we didn't differentiate between model install errors for different types of model install sources, resulting in a buggy UX:
- If a HF model install failed, but it was a HF URL install and not a repo id install, the link to the HF model page was incorrect.
- If a non-HF URL install (e.g. civitai) failed, we treated it as a HF URL install. In this case, if the user's HF token was invalid or unset, we directed the user to set it. If the HF token was valid, we displayed an empty red toast. If it's not a HF URL install, then of course neither of these are correct.

Also, the logic for handling the toasts was a bit complicated.

This change does a few things:
- Consolidate the model install error toasts into one place - the socket.io event handler for the model install error event. There is no more global state for the toasts and there are no hooks managing them.
- Handling the different cases for errors, including all combinations of HF/non-HF and unauthorized/forbidden/unknown.
For example, "flux" now matches any starter model with a model base of "FLUX".
@hipsterusername hipsterusername force-pushed the psyche/feat/mm-auth-handling branch from a5a796f to 9525c38 Compare January 3, 2025 16:12
@hipsterusername hipsterusername enabled auto-merge (rebase) January 3, 2025 16:12
@hipsterusername hipsterusername merged commit 868e06e into main Jan 3, 2025
15 checks passed
@hipsterusername hipsterusername deleted the psyche/feat/mm-auth-handling branch January 3, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs PRs that change docs frontend PRs that change frontend files python PRs that change python files python-tests PRs that change python tests services PRs that change app services
Projects
None yet
3 participants