Skip to content

Commit cbb857b

Browse files
committed
enable creating embedding with --medvram
1 parent ee73341 commit cbb857b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

modules/textual_inversion/textual_inversion.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ def create_embedding(name, num_vectors_per_token, overwrite_old, init_text='*'):
157157
cond_model = shared.sd_model.cond_stage_model
158158
embedding_layer = cond_model.wrapped.transformer.text_model.embeddings
159159

160+
with devices.autocast():
161+
cond_model([""]) # will send cond model to GPU if lowvram/medvram is active
162+
160163
ids = cond_model.tokenizer(init_text, max_length=num_vectors_per_token, return_tensors="pt", add_special_tokens=False)["input_ids"]
161164
embedded = embedding_layer.token_embedding.wrapped(ids.to(devices.device)).squeeze(0)
162165
vec = torch.zeros((num_vectors_per_token, embedded.shape[1]), device=devices.device)

0 commit comments

Comments
 (0)