Skip to content

Commit

Permalink
Adding support for FastComposer
Browse files Browse the repository at this point in the history
 add device for running with cuda by default
  • Loading branch information
xiaomile committed Sep 8, 2023
1 parent 312c5f0 commit 4bbacbb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 4 additions & 1 deletion configs/fastcomposer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ if num_subject_in_text != len(image):
if seed == -1:
seed = np.random.randint(0, 1000000)

generator = torch.manual_seed(seed)
device = torch.device('cuda' if torch.cuda.is_available(
) else 'cpu')
generator = torch.Generator(device=device)
generator.manual_seed(seed)

output_dict = fastcomposer.infer(prompt,
negative_prompt=negative_prompt,
Expand Down
5 changes: 4 additions & 1 deletion configs/fastcomposer/README_zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ if num_subject_in_text != len(image):
if seed == -1:
seed = np.random.randint(0, 1000000)

generator = torch.manual_seed(seed)
device = torch.device('cuda' if torch.cuda.is_available(
) else 'cpu')
generator = torch.Generator(device=device)
generator.manual_seed(seed)

output_dict = fastcomposer.infer(prompt,
negative_prompt=negative_prompt,
Expand Down
6 changes: 5 additions & 1 deletion demo/gradio_fastcomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ModelWrapper:
def __init__(self, model):
super().__init__()
self.model = model
self.device = torch.device(
'cuda' if torch.cuda.is_available() else 'cpu')
self.model = self.model.to(self.device)

def inference(
self,
Expand Down Expand Up @@ -58,7 +61,8 @@ def inference(
if seed == -1:
seed = np.random.randint(0, 1000000)

generator = torch.manual_seed(seed)
generator = torch.Generator(device=self.device)
generator.manual_seed(seed)

return (
self.model.infer(
Expand Down

0 comments on commit 4bbacbb

Please sign in to comment.