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

added hf models import tab and route for getting available hf models #5891

Merged
merged 14 commits into from Mar 13, 2024

Conversation

chainchompa
Copy link
Collaborator

@chainchompa chainchompa commented Mar 7, 2024

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update
  • Community Node Submission

Have you discussed this change with the InvokeAI team?

  • Yes
  • No, because:

Have you updated all relevant documentation?

  • Yes
  • No

Description

  • added tab for installing hugging face models to mm which checks for files in repo and either installs them or displays if more than one model is available

Related Tickets & Documents

  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Merge Plan

Added/updated tests?

  • Yes
  • No : please replace this line with details on why tests
    have not been included

[optional] Are there any post deployment tasks we need to perform?

@github-actions github-actions bot added api python PRs that change python files backend PRs that change backend files services PRs that change app services frontend PRs that change frontend files labels Mar 7, 2024
@chainchompa chainchompa changed the title added hf models import tab and route for getting available hf models WIP: added hf models import tab and route for getting available hf models Mar 7, 2024
Copy link
Collaborator

@psychedelicious psychedelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should change any model install files, or select_hf_files.py. That's all fairly sensitive logic.

Calling HuggingFaceMetadata.download_urls() does filtering to figure out which URLs it needs to download for diffusers-format models, but for this feature, we want to list all files in the repo.

HuggingFaceMetadata.files will have all files, and we can show that in the UI. Then I think we want to offer two options.

  1. Install this whole HF repo as a single diffusers model.

We can check for the presence of a model_index.json file, which indicates the repo is a diffusers format model. If that exists, we can hint to install as diffusers.

If the user chooses this option, we'd hit the /install route with the repo id to initiate the download.

We could also offer a choice of repo variant - probably FP16, FP32 and a default (None). I don't think the other values are actually support by invoke. I'm not sure if this is necessary though.

  1. Install a specific checkpoint file from within the repo.

We'd suggest this if there is no mode_index.json file. In this case, users would select an individual file to install as a checkpoint model file.

In this case, we hit the /install route with the .url of the file - e.g. HuggingFaceMetadata.files[selectedFileIndex].url.

@chainchompa chainchompa changed the title WIP: added hf models import tab and route for getting available hf models added hf models import tab and route for getting available hf models Mar 11, 2024
@chainchompa chainchompa marked this pull request as ready for review March 11, 2024 16:14
Copy link
Collaborator

@maryhipp maryhipp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worked well for me!

Copy link
Collaborator

@psychedelicious psychedelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are doing just a bit too much on the frontend by letting it decide what kind of models are available in the HF api response.

Suggest extending HuggingFaceMetadata with is_diffusers and ckpt_urls:

class HuggingFaceMetadata(ModelMetadataWithFiles):
    """Extended metadata fields provided by HuggingFace."""

    type: Literal["huggingface"] = "huggingface"
    id: str = Field(description="The HF model id")
    api_response: Optional[str] = Field(description="Response from the HF API as stringified JSON", default=None)
    is_diffusers: bool = Field(description="Whether the metadata is for a Diffusers format model")
    ckpt_urls: Optional[List[AnyHttpUrl]] = Field(
        description="URLs for all checkpoint format models in the metadata", default=None
    )

Then, in HuggingFaceMetadataFetch, figure these attrs out:

class HuggingFaceMetadataFetch(ModelMetadataFetchBase):
    ...
    def from_id(self, id: str, variant: Optional[ModelRepoVariant] = None) -> AnyModelRepoMetadata:
        ...
        # diffusers models have a `model_index.json` file
        is_diffusers = any(str(f.url).endswith("model_index.json") for f in files)
        
        # These URLs will be exposed to the user - I think these are the only file types we fully support
        ckpt_urls = (
            None
            if is_diffusers
            else [
                f.url
                for f in files
                if str(f.url).endswith(
                    (
                        ".safetensors",
                        ".bin",
                        ".pth",
                        ".pt",
                        ".ckpt",
                    )
                )
            ]
        )

        return HuggingFaceMetadata(
            id=model_info.id,
            name=name,
            files=files,
            api_response=json.dumps(model_info.__dict__, default=str),
            is_diffusers=is_diffusers,
            ckpt_urls=ckpt_urls,
        )

The UI can then also more easily handle the case where a repo ID is provided that has no models in it.

@psychedelicious psychedelicious enabled auto-merge (rebase) March 13, 2024 06:09
auto-merge was automatically disabled March 13, 2024 06:16

Rebase failed

@psychedelicious
Copy link
Collaborator

psychedelicious commented Mar 13, 2024

Thanks @chainchompa ! I did a styling pass and updated some of the verbiage.

Screen.Recording.2024-03-13.at.8.54.58.pm.mov

There appears to be some jank in the Tab components that causes weird overflow, which you had worked through using margins. I fiddled around and found adding display="flex" flexDir="column" to <Tabs /> fixed the root cause and fix the overflow. I'll address this in the UI library later.

@psychedelicious psychedelicious merged commit 614fece into main Mar 13, 2024
14 checks passed
@psychedelicious psychedelicious deleted the chainchompa/mm-safetensors branch March 13, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api backend PRs that change backend files frontend PRs that change frontend files python PRs that change python files services PRs that change app services
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants