Unconditional Image Generation
Transformers
Safetensors
tinyimagegen
feature-extraction
imagegen
unconditional-image
custom_code
Instructions to use fromziro/TinyImageGen-0.6M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use fromziro/TinyImageGen-0.6M with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("fromziro/TinyImageGen-0.6M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload 3 files
Browse files- config.json +1 -1
- configuration_tinyimagegen.py +1 -1
- modeling_tinyimagegen.py +10 -2
config.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
"AutoConfig": "configuration_tinyimagegen.TinyImageGenConfig",
|
| 7 |
-
"AutoModel": "modeling_tinyimagegen.
|
| 8 |
"AutoModelForImageDiffusion": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion"
|
| 9 |
},
|
| 10 |
"dtype": "float32",
|
|
|
|
| 4 |
],
|
| 5 |
"auto_map": {
|
| 6 |
"AutoConfig": "configuration_tinyimagegen.TinyImageGenConfig",
|
| 7 |
+
"AutoModel": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion",
|
| 8 |
"AutoModelForImageDiffusion": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion"
|
| 9 |
},
|
| 10 |
"dtype": "float32",
|
configuration_tinyimagegen.py
CHANGED
|
@@ -44,7 +44,7 @@ class TinyImageGenConfig(PretrainedConfig):
|
|
| 44 |
|
| 45 |
self.auto_map = {
|
| 46 |
"AutoConfig": "configuration_tinyimagegen.TinyImageGenConfig",
|
| 47 |
-
"AutoModel": "modeling_tinyimagegen.
|
| 48 |
"AutoModelForImageDiffusion": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion",
|
| 49 |
}
|
| 50 |
|
|
|
|
| 44 |
|
| 45 |
self.auto_map = {
|
| 46 |
"AutoConfig": "configuration_tinyimagegen.TinyImageGenConfig",
|
| 47 |
+
"AutoModel": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion",
|
| 48 |
"AutoModelForImageDiffusion": "modeling_tinyimagegen.TinyImageGenModelForImageDiffusion",
|
| 49 |
}
|
| 50 |
|
modeling_tinyimagegen.py
CHANGED
|
@@ -292,13 +292,21 @@ class TinyImageGenPreTrainedModel(PreTrainedModel):
|
|
| 292 |
|
| 293 |
if os.path.exists(st_file):
|
| 294 |
state_dict = load_file(st_file)
|
| 295 |
-
model.load_state_dict(state_dict, strict=False)
|
| 296 |
elif os.path.exists(bin_file):
|
| 297 |
state_dict = torch.load(bin_file, map_location="cpu")
|
| 298 |
-
model.load_state_dict(state_dict, strict=False)
|
| 299 |
else:
|
| 300 |
return super().from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)
|
| 301 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 302 |
if torch_dtype is not None:
|
| 303 |
model.to(dtype=torch_dtype)
|
| 304 |
|
|
|
|
| 292 |
|
| 293 |
if os.path.exists(st_file):
|
| 294 |
state_dict = load_file(st_file)
|
|
|
|
| 295 |
elif os.path.exists(bin_file):
|
| 296 |
state_dict = torch.load(bin_file, map_location="cpu")
|
|
|
|
| 297 |
else:
|
| 298 |
return super().from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)
|
| 299 |
|
| 300 |
+
model_keys = set(model.state_dict().keys())
|
| 301 |
+
st_keys = set(state_dict.keys())
|
| 302 |
+
if not model_keys.intersection(st_keys):
|
| 303 |
+
if any(k.startswith("model.") for k in st_keys):
|
| 304 |
+
state_dict = {k[6:] if k.startswith("model.") else k: v for k, v in state_dict.items()}
|
| 305 |
+
elif any(k.startswith("model.") for k in model_keys):
|
| 306 |
+
state_dict = {f"model.{k}": v for k, v in state_dict.items()}
|
| 307 |
+
|
| 308 |
+
model.load_state_dict(state_dict, strict=True)
|
| 309 |
+
|
| 310 |
if torch_dtype is not None:
|
| 311 |
model.to(dtype=torch_dtype)
|
| 312 |
|