manbeast3b commited on
Commit
c3208ec
·
verified ·
1 Parent(s): 3a4ac2d

Update src/pipeline.py

Browse files
Files changed (1) hide show
  1. src/pipeline.py +5 -35
src/pipeline.py CHANGED
@@ -136,42 +136,12 @@ def load_pipeline() -> Pipeline:
136
  return pipeline
137
 
138
 
139
-
140
- _inference_count = 0
141
-
142
  @torch.inference_mode()
143
  def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
144
- global _inference_count
145
- # Clear on first inference
146
- if _inference_count == 0:
147
- empty_cache()
148
-
149
- # Increment counter and empty cache every 4 inferences
150
- _inference_count += 1
151
- if _inference_count >= 4:
152
- empty_cache()
153
- _inference_count = 0
154
-
155
- torch.cuda.reset_peak_memory_stats()
156
- generator = Generator("cuda").manual_seed(request.seed)
157
- image = pipeline(
158
- prompt=request.prompt,
159
- generator=generator,
160
- guidance_scale=0.0,
161
- num_inference_steps=4,
162
- max_sequence_length=256,
163
- height=request.height,
164
- width=request.width,
165
- output_type="pt"
166
- ).images[0]
167
- return torchvision.transforms.functional.to_pil_image(image.to(torch.float32).mul_(2).sub_(1))
168
 
169
- # @torch.inference_mode()
170
- # def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
171
- # generator = Generator(pipeline.device).manual_seed(request.seed)
172
- # # image=pipeline(request.prompt,generator=generator, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, height=request.height, width=request.width, output_type="pil").images[0]
173
-
174
- # # return(image)
175
 
176
- # image=pipeline(request.prompt,generator=generator, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, height=request.height, width=request.width, output_type="pt").images[0]
177
- # return torchvision.transforms.functional.to_pil_image(image.to(torch.float32).mul_(2).sub_(1))
 
136
  return pipeline
137
 
138
 
 
 
 
139
  @torch.inference_mode()
140
  def infer(request: TextToImageRequest, pipeline: Pipeline) -> Image:
141
+ generator = Generator(pipeline.device).manual_seed(request.seed)
142
+ # image=pipeline(request.prompt,generator=generator, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, height=request.height, width=request.width, output_type="pil").images[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
+ # return(image)
 
 
 
 
 
145
 
146
+ image=pipeline(request.prompt,generator=generator, guidance_scale=0.0, num_inference_steps=4, max_sequence_length=256, height=request.height, width=request.width, output_type="pt").images[0]
147
+ return torchvision.transforms.functional.to_pil_image(image.to(torch.float32).mul_(2).sub_(1))