-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark_oneflow.py
65 lines (56 loc) · 1.62 KB
/
benchmark_oneflow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations
from functools import partial
import fal
from benchmarks.settings import BenchmarkResults, BenchmarkSettings, InputParameters
@fal.function(
requirements=[
"--pre",
"torch>=2.1.0",
"transformers>=4.27.1",
"diffusers>=0.19.3",
"git+https://github.com/Oneflow-Inc/[email protected]",
"oneflow",
"-f",
"https://oneflow-pro.oss-cn-beijing.aliyuncs.com/branch/community/cu121",
],
machine_type="GPU",
)
def oneflow_any(
benchmark_settings: BenchmarkSettings,
parameters: InputParameters,
model_name: str,
) -> BenchmarkResults:
import oneflow as flow
import torch
from diffusers import DiffusionPipeline
from onediff.infer_compiler import oneflow_compile
pipeline = DiffusionPipeline.from_pretrained(
model_name,
torch_dtype=torch.float16,
use_safetensors=True,
)
pipeline.to("cuda")
pipeline.unet = oneflow_compile(pipeline.unet)
with flow.autocast("cuda"):
infer_func = partial(
pipeline, parameters.prompt, num_inference_steps=parameters.steps
)
return benchmark_settings.apply(infer_func)
LOCAL_BENCHMARKS = [
{
"name": "OneFlow",
"category": "SD1.5 (End-to-end)",
"function": oneflow_any,
"kwargs": {
"model_name": "runwayml/stable-diffusion-v1-5",
},
},
{
"name": "OneFlow",
"category": "SDXL (End-to-end)",
"function": oneflow_any,
"kwargs": {
"model_name": "stabilityai/stable-diffusion-xl-base-1.0",
},
},
]