-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Allow Automodel to use from_config with custom code.
#13123
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
Open
DN6
wants to merge
2
commits into
main
Choose a base branch
from
automodel-from-config
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh I think maybe we should support this in
from_pretrained()? even for scheduler and such weightless things, we load them usingfrom_pretrained(), no?we normally use
from_configlike this, would be confusing I thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is true. But the SchedulerMixin's
from_pretrainedjust runsfrom_configunder the hood.diffusers/src/diffusers/schedulers/scheduling_utils.py
Lines 147 to 154 in 985d83c
I thought perhaps we could make an exception for just the AutoModel class? The
load_configand thenfrom_configflow doesn't work too well when trying to load custom code.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohh thanks for explaining. I think I got it now.
but is it possible to not re-use the
from_configAPI with a different usage pattern? I think maybe we can add a new arg tofrom_pretrainedto support this use case? e.gload_weights=True,init_from_config=FalseetcEven for custom components that come with the weights, we neeed to support for this use case, for example training, or stuff like here we need to initialize it to inspect model structure for quantisation https://github.com/cubiq/Mellon/blob/main/modules/ModularDiffusers/loaders.py#L181
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or maybe a brand new method if it you prefer
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init_from_hub? from_pretrained_config? etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO
from_configis the preferred option because it works well with ComponentSpec'sdefault_creation_methodas well. So we don't need to introduce too many changes to modular get this functionality.Models currently support passing in a
pretrained_model_name_or_path. I know that there was a plan to deprecate this behaviour (but I'm not clear as to why the deprecation is needed?)diffusers/src/diffusers/configuration_utils.py
Lines 237 to 251 in 76af013
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's before my time in but if I have to guess, they deprecated it after adding
from_pretrained()toschedulerto make API cleaner:from_pretrainedhandles loading (without or without weights) andfrom_configtakes onlyconfig dictso if we undo the deprecation & introduce the from_config on AutoModel, the mental model would be something like this?
from_pretrainedcreate the model with the hub_id with default behavior: load weigths for models, create config for weightless things) and this correspond so thedefault_creation_methodin ComponentSpecfrom_configis used to explicitly create from config without weights, acccept both a config dict and paththis sounds fine to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note on this though —
default_creation_methodis currently aligned with the currentfrom_pretrained/from_configusage. e.g. the default creation method would befrom_pretrainedfor weightless components as long as it needs to load a config from hub,image processorusesfrom_configbecause it's created from a config dict defined in componenet spec directlynot sure if this complicates anything so just something to keep in mind