Skip to content

Commit

Permalink
Add stable-diffusion in dicp tops ci.
Browse files Browse the repository at this point in the history
  • Loading branch information
yao-fengchen committed Dec 26, 2023
1 parent 0edf815 commit f93d535
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/_runs-on-topsrider.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ jobs:
pip uninstall dicp -y && \
cd dipu && python setup.py install --user && \
cd ../dicp && python setup.py install --user && \
cd .. && source dicp/scripts/ci/tops/ci_tops_test_env.sh /mnt/models/llama_models && \
cd .. && source dicp/scripts/ci/tops/ci_tops_test_env.sh \
/mnt/models/llama_models /mnt/models/stable_diffusion_models && \
export TEST_DIR=$(pwd)/dicp/test && echo ${TEST_DIR} && \
bash ${TEST_DIR}/tops_scripts/ops/run_test_ops.sh false && \
bash ${TEST_DIR}/tops_scripts/models/run_test_models.sh false
bash ${TEST_DIR}/model/run_test_model.sh llama topsgraph false && \
bash ${TEST_DIR}/model/run_test_model.sh resnet50 topsgraph false && \
bash ${TEST_DIR}/model/run_test_model.sh stable_diffusion topsgraph false
"
job_name: "build_test"
cover_job: "0"
1 change: 1 addition & 0 deletions dicp/scripts/ci/tops/ci_tops_test_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ LLAMA_MODEL_DIR=$1
STABLE_DIFFUSION_MODEL_DIR=$2

export DIPU_MOCK_CUDA=false
export ENFLAME_LOG_LEVEL=ERROR
export LLAMA_MODEL_DIR=$1
export STABLE_DIFFUSION_MODEL_DIR=$2
1 change: 1 addition & 0 deletions dicp/test/model/stable_diffusion/topsgraph_output.txt

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions dicp/test/model/test_stable_diffusion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import pytest
import torch
import os
import torch._dynamo as dynamo
from ..common import utils
import torch_dipu
from diffusers import StableDiffusionPipeline
dynamo.config.cache_size_limit = 128
utils.update_dynamo_config(False)
device = utils.get_device()
torch_dipu.dipu.set_device(device)
models_dir = os.environ.get("STABLE_DIFFUSION_MODEL_DIR")
assert models_dir is not None


class TestLlama():
@pytest.mark.parametrize("model_path", [f"{models_dir}/stable-diffusion-2"])
@pytest.mark.parametrize("num_inference_steps", [50])
def test_inference(
self,
model_path: str,
backend: str,
dynamic: bool,
num_inference_steps: int
):
prompt = "A photo of an astronaut riding a horse on mars."
utils.update_dynamo_config(dynamic=dynamic)
torch_dipu.dipu.set_device(device)

dicp_pipe = StableDiffusionPipeline.from_pretrained(model_path).to(device)
dicp_pipe.text_encoder = torch.compile(dicp_pipe.text_encoder, backend=backend)
dicp_pipe.unet = torch.compile(dicp_pipe.unet, backend=backend)
dicp_image = dicp_pipe(prompt, num_inference_steps=num_inference_steps).images[0]
if backend == "ascendgraph":
with open("stable_diffusion/topsgraph_output.txt", "r") as f:
standard_output = eval(f.read())
elif backend == "topsgraph":
with open("stable_diffusion/topsgraph_output.txt", "r") as f:
standard_output = eval(f.read())
else:
raise ValueError("backend should in (ascendgrap, topsgraph)")
dicp_output = list(dicp_image.getdata())
same = 0
for i, item in enumerate(standard_output):
same += 1 if dicp_output[i] == item else 0
assert len(standard_output) == len(dicp_output) and same / len(standard_output) >= 0.999

0 comments on commit f93d535

Please sign in to comment.