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

[DRAFT] Support multiple tokenizers and other layers with assets #1860

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattdangerw
Copy link
Member

@mattdangerw mattdangerw commented Sep 22, 2024

Preset saving and loading does not currently generalize to multiple tokenizers (or other preprocessor with static assets), this is a work in progress PR towards adding it, specifically for stable diffusion.

The high-level api would allow something like this

# High-level loading.
image_to_text = keras_hub.models.ImageToText.from_preset(
    "sd3_preset_name",
)
# Low-level tokenizer loading.
clip_l_tokenizer = kersa_hub.tokenizers.Tokenizer.from_preset(
    "sd3_preset_name", config_file="clip_l_tokenizer.json",
)
clip_g_tokenizer = kersa_hub.tokenizers.Tokenizer.from_preset(
    "sd3_preset_name", config_file="clip_g_tokenizer.json",
)

During conversion, we would need to make sure each tokenizer was created with a separate config_file passed to the constructor. Then when calling task.save_to_preset("path"), you would get the following structure.

assets/clip_l_tokenizer/...
assets/clip_g_tokenizer/...
assets/t5_tokenizer/...
clip_l_tokenizer.json
clip_g_tokenizer.json
t5_tokenizer.json

This is just a WIP commit to share with @james77777778 , tests will not pass yet.

Preset saving and loading does not currently generalize to multiple
tokenizers (or other preprocessor with static assets), this is a work
in progress PR towards adding it, specifically for stable diffusion.

The high-level api would allow something like this

```python
# High-level loading.
image_to_text = keras_hub.models.ImageToText.from_preset(
    "sd3_preset",
)
# Low-level tokenizer loading.
clip_l_tokenizer = kersa_hub.tokenizers.Tokenizer.from_preset(
    "sd3_preset", config_file="clip_l_tokenizer.json",
)
clip_g_tokenizer = kersa_hub.tokenizers.Tokenizer.from_preset(
    "sd3_preset", config_file="clip_g_tokenizer.json",
)
```

During conversion, we would need to make sure each tokenizer was
created with a separate `config_file` passed to the constructor. Then
when calling `task.save_to_preset("path")`, you would get the following
structure.

```
assets/clip_l_tokenizer/...
assets/clip_g_tokenizer/...
assets/t5_tokenizer/...
clip_l_tokenizer.json
clip_g_tokenizer.json
t5_tokenizer.json
```
@mattdangerw
Copy link
Member Author

@james77777778 just creating this to share a possible solution to #1820 (comment), feel free to patch in and play around. Though I would still merge #1820 without a solution here so we can stay incremental.

@mattdangerw mattdangerw mentioned this pull request Sep 22, 2024
4 tasks
@james77777778
Copy link
Collaborator

I will try this PR when porting the weights of SD3.
Should I take over this PR, or will you merge it?

@divyashreepathihalli
Copy link
Collaborator

I will try this PR when porting the weights of SD3. Should I take over this PR, or will you merge it?

Hi James! Please feel free to take this PR up.

@mattdangerw
Copy link
Member Author

Yes sorry for the delay, but please take this PR up. Let's test this out with sd3

1 similar comment
@mattdangerw
Copy link
Member Author

Yes sorry for the delay, but please take this PR up. Let's test this out with sd3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants