Skip to content

Commit bc9483d

Browse files
committed
Don't update base conda, x_m_e_a call toggle, drop conda cache
1 parent 8cdf215 commit bc9483d

File tree

5 files changed

+19
-10
lines changed

5 files changed

+19
-10
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ WORKDIR /api
3030

3131
# We need python 3.9 or 3.10 for xformers
3232
# Yes, we install pytorch twice... will switch base image in future
33-
RUN mkdir -p /opt/conda/pkgs
34-
COPY /conda-pkgs/* /opt/conda/pkgs/
35-
RUN conda update -n base -c defaults conda
33+
# RUN conda update -n base -c defaults conda
3634
RUN conda create -n xformers python=3.10
3735
SHELL ["/opt/conda/bin/conda", "run", "--no-capture-output", "-n", "xformers", "/bin/bash", "-c"]
3836
RUN python --version

app.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,27 @@ def inference(all_inputs: dict) -> dict:
273273
mask = mask.repeat(8, axis=0).repeat(8, axis=1)
274274
model_inputs["mask_image"] = PIL.Image.fromarray(mask)
275275

276+
x_m_e_a = call_inputs.get("xformers_memory_efficient_attention", None)
277+
if x_m_e_a == None:
278+
pipeline.enable_xformers_memory_efficient_attention() # default on
279+
elif x_m_e_a == True:
280+
pipeline.enable_xformers_memory_efficient_attention()
281+
elif x_m_e_a == False:
282+
pipeline.disable_xformers_memory_efficient_attention()
283+
else:
284+
return {
285+
"$error": {
286+
"code": "INVALID_XFORMERS_MEMORY_EFFICIENT_ATTENTION_VALUE",
287+
"message": f'Model "{model_id}" not available on this container which hosts "{MODEL_ID}"',
288+
"requested": x_m_e_a,
289+
"available": [True, False],
290+
}
291+
}
292+
276293
# Run the model
277294
# with autocast("cuda"):
278295
# image = pipeline(**model_inputs).images[0]
279296

280-
pipeline.enable_xformers_memory_efficient_attention()
281-
282297
with torch.inference_mode():
283298
# autocast im2img and inpaint which are broken in 0.4.0, 0.4.1
284299
# still broken in 0.5.1

conda-pkgs/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

conda-pkgs/README.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def runTest(name, banana):
119119
"MODEL_ID": "runwayml/stable-diffusion-v1-5",
120120
"PIPELINE": "StableDiffusionPipeline",
121121
"SCHEDULER": "LMS",
122+
# "xformers_memory_efficient_attention": False,
122123
},
123124
},
124125
)

0 commit comments

Comments
 (0)