AutoModel¶
The AutoModel
is designed to make it easy to load a checkpoint without needing to know the specific model class. AutoModel
automatically retrieves the correct model class from the checkpoint config.json
file.
from mindone.diffusers import AutoModel, AutoPipelineForText2Image
unet = AutoModel.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", subfolder="unet")
pipe = AutoPipelineForText2Image.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", unet=unet)
mindone.diffusers.AutoModel
¶
Bases: ConfigMixin
Source code in mindone/diffusers/models/auto_model.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|
mindone.diffusers.AutoModel.from_pretrained(pretrained_model_or_path=None, **kwargs)
classmethod
¶
Instantiate a pretrained MindSpore model from a pretrained model configuration.
The model is set in evaluation mode - model.eval()
- by default, and dropout modules are deactivated. To
train the model, set it back in training mode with model.train()
.
PARAMETER | DESCRIPTION |
---|---|
pretrained_model_name_or_path |
Can be either:
TYPE:
|
cache_dir |
Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.
TYPE:
|
mindspore_dtype |
Override the default
TYPE:
|
force_download |
Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
TYPE:
|
proxies |
A dictionary of proxy servers to use by protocol or endpoint, for example,
TYPE:
|
output_loading_info |
Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
TYPE:
|
local_files_only(`bool`, |
Whether to only load local model weights and configuration files or not. If set to
TYPE:
|
token |
The token to use as HTTP bearer authorization for remote files. If
TYPE:
|
revision |
The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.
TYPE:
|
from_flax |
Load the model weights from a Flax checkpoint save file.
TYPE:
|
subfolder |
The subfolder location of a model file within a larger model repository on the Hub or locally.
TYPE:
|
mirror |
Mirror source to resolve accessibility issues if you're downloading a model in China. We do not guarantee the timeliness or safety of the source, and you should refer to the mirror site for more information.
TYPE:
|
max_memory |
A dictionary device identifier for the maximum memory. Will default to the maximum memory available for each GPU and the available CPU RAM if unset.
TYPE:
|
offload_folder |
The path to offload weights if
TYPE:
|
offload_state_dict |
If
TYPE:
|
variant |
Load weights from a specified
TYPE:
|
use_safetensors |
If set to
TYPE:
|
disable_mmap |
Whether to disable mmap when loading a Safetensors model. This option can perform better when the model is on a network mount or hard drive, which may not handle the seeky-ness of mmap very well.
TYPE:
|
To use private or gated models, log-in with
huggingface-cli login
. You can also activate the special
"offline-mode" to use this method in a
firewalled environment.
Example:
from mindone.diffusers import AutoModel
unet = AutoModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet")
If you get the error message below, you need to finetune the weights for your downstream task:
Some weights of UNet2DConditionModel were not initialized from the model checkpoint at runwayml/stable-diffusion-v1-5 and are newly initialized because the shapes did not match: # noqa
- conv_in.weight: found shape mindspore.Size([320, 4, 3, 3]) in the checkpoint and mindspore.Size([320, 9, 3, 3]) in the model instantiated
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
Source code in mindone/diffusers/models/auto_model.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|