hpcaitech / Open-Sora

Open-Sora: Democratizing Efficient Video Production for All
https://hpcaitech.github.io/Open-Sora/
Apache License 2.0
20.1k stars 1.91k forks source link

How to add negative prompts? #544

Closed rob-hen closed 1 week ago

rob-hen commented 1 week ago

How can we use negative prompts with the framework?

I thought to replace this line https://github.com/hpcaitech/Open-Sora/blob/0312a0d85290eeb5c04f122c3688baaa0f8d9c8c/opensora/schedulers/iddpm/__init__.py#L69 with this line:

if use_negative_prompts:
  model_args_negative = text_encoder.encode(negative_prompts)
  y_null = model_args_negative["y"]
else:
  y_null = text_encoder.null(n)

However, the result looks wrong. Do you have any idea how it can be integrated?

rob-hen commented 1 week ago

Its now working, we also have to update the mask:

model_args["mask"] = torch.cat([model_args["mask"], model_args_negative["mask"]],dim=0)

rob-hen commented 1 week ago

@zhengzangw May be you want to add it to your code as well.