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

Support notebook execution on smaller devices #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion notebooks/T2I_sampling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@
"you can input various texts to generate the corresponded images. \n",
"\n",
"You can certainly adjust the sampling parameters such as `temperature`, `top_k`, and `top_p` for better quality of generated images according to the given texts. \n",
"As the three parameters have lower values than the default setting, you can get more simple and confident images, and vice versa."
"As the three parameters have lower values than the default setting, you can get more simple and confident images, and vice versa.\n",
"\n",
"### Execution on local machines\n",
"If running locally on a smaller device with enough memory to load the model (e.g. RTX 3090,) first make the following changes:\n",
"1. Add `map_location='cuda'` to both `load_model` calls in step 2.\n",
"2. Reduce the `num_samples` in step 3 to meet your memory constraints.\n",
"3. Add `amp=False` to the `get_generated_images_by_texts` call in step 4."
]
},
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/notebook_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ def __call__(self, texts):
return self.encode(texts)


def load_model(path, ema=False):
def load_model(path, ema=False, map_location='cpu'):
model_config = os.path.join(os.path.dirname(path), 'config.yaml')
config = load_config(model_config)
config.arch = augment_arch_defaults(config.arch)

model, _ = create_model(config.arch, ema=False)
if ema:
ckpt = torch.load(path, map_location='cpu')['state_dict_ema']
ckpt = torch.load(path, map_location=map_location)['state_dict_ema']
else:
ckpt = torch.load(path, map_location='cpu')['state_dict']
ckpt = torch.load(path, map_location=map_location)['state_dict']
model.load_state_dict(ckpt)

return model, config
Expand Down