From f9d2bd24eba010a461a75e2746f2ccc403c87aad Mon Sep 17 00:00:00 2001 From: Max Cohen Date: Mon, 4 Sep 2023 17:10:55 +0000 Subject: [PATCH] Allow to manually set the seed for the SD pipeline (#998) **Description** Enable setting the seed for the stable diffusion pipeline. This is done through an additional `seed` parameter in the request, such as: ```bash curl http://localhost:8080/v1/images/generations \ -H "Content-Type: application/json" \ -d '{"model": "stablediffusion", "prompt": "prompt", "n": 1, "step": 51, "size": "512x512", "seed": 3}' ``` **Notes for Reviewers** When the `seed` parameter is not sent, `request.seed` defaults to `0`, making it difficult to detect an actual seed of `0`. Is there a way to change the default to `-1` for instance ? **[Signed commits](../CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin)** - [x] Yes, I signed my commits. --- extra/grpc/diffusers/backend_diffusers.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/extra/grpc/diffusers/backend_diffusers.py b/extra/grpc/diffusers/backend_diffusers.py index cff461f8..bb7d991a 100755 --- a/extra/grpc/diffusers/backend_diffusers.py +++ b/extra/grpc/diffusers/backend_diffusers.py @@ -300,6 +300,7 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): "width": request.width, "height": request.height, "num_inference_steps": request.step, + "seed": request.seed, } if request.src != "": @@ -318,6 +319,12 @@ class BackendServicer(backend_pb2_grpc.BackendServicer): # create a dictionary of parameters by using the keys from EnableParameters and the values from defaults kwargs = {key: options[key] for key in keys} + # Set seed + if request.seed > 0: + kwargs["generator"] = torch.Generator(device="cuda").manual_seed( + request.seed + ) + image = {} if COMPEL: conditioning = self.compel.build_conditioning_tensor(prompt)