John6666 commited on
Commit
1cee750
Β·
verified Β·
1 Parent(s): 9918025

Upload 3 files

Browse files
Files changed (3) hide show
  1. README.md +13 -12
  2. app.py +88 -0
  3. requirements.txt +11 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
- ---
2
- title: Torch Compile Bug
3
- emoji: πŸŒ–
4
- colorFrom: purple
5
- colorTo: red
6
- sdk: gradio
7
- sdk_version: 5.20.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
1
+ ---
2
+ title: BUG? - strange behaviour of torch.compile() in Hugging Face Spaces and Endpoint API (dedicated)
3
+ emoji: πŸ™„
4
+ colorFrom: yellow
5
+ colorTo: pink
6
+ sdk: gradio
7
+ sdk_version: 5.20.0
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ ---
12
+
13
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import spaces
2
+ import gradio as gr
3
+ import torch
4
+ import os
5
+ from diffusers import DiffusionPipeline
6
+ import torch._dynamo
7
+ torch._dynamo.config.suppress_errors = False
8
+ torch._inductor.config.disable_progress = False
9
+
10
+ print(os.environ)
11
+ import subprocess
12
+ subprocess.run("pip list", shell=True)
13
+
14
+ dtype = torch.float32
15
+ device = "cuda" if torch.cuda.is_available() else "cpu"
16
+ repo_id = "stable-diffusion-v1-5/stable-diffusion-v1-5"
17
+ pipe = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=dtype)
18
+ pipe.unet = torch.compile(pipe.unet, mode="max-autotune", fullgraph=True)
19
+ pipe.to(device)
20
+
21
+ pipe2 = DiffusionPipeline.from_pretrained(repo_id, torch_dtype=dtype)
22
+ pipe2.to(device)
23
+
24
+ @spaces.GPU(duration=59)
25
+ def infer(prompt: str, progress=gr.Progress(track_tqdm=True)):
26
+ image = pipe(
27
+ prompt=prompt,
28
+ output_type="pil",
29
+ ).images[0]
30
+ return image
31
+
32
+ @spaces.GPU(duration=59)
33
+ def infer2(prompt: str, progress=gr.Progress(track_tqdm=True)):
34
+ image = pipe2(
35
+ prompt=prompt,
36
+ output_type="pil",
37
+ ).images[0]
38
+ return image
39
+
40
+ examples = [
41
+ "a tiny astronaut hatching from an egg on the moon",
42
+ "a cat holding a sign that says hello world",
43
+ "an anime illustration of a wiener schnitzel",
44
+ ]
45
+
46
+ css="""
47
+ #col-container {
48
+ margin: 0 auto;
49
+ max-width: 520px;
50
+ }
51
+ """
52
+
53
+ with gr.Blocks(css=css) as demo:
54
+ with gr.Column(elem_id="col-container"):
55
+
56
+ with gr.Row():
57
+
58
+ prompt = gr.Text(
59
+ label="Prompt",
60
+ show_label=False,
61
+ max_lines=1,
62
+ placeholder="Enter your prompt",
63
+ container=False,
64
+ )
65
+
66
+ run_button = gr.Button("Run with torch.compile()", scale=0)
67
+ run_button2 = gr.Button("Run without torch.compile()", scale=0)
68
+
69
+ result = gr.Image(label="Result", show_label=False)
70
+
71
+ gr.Examples(
72
+ examples=examples,
73
+ #fn=infer,
74
+ inputs=[prompt],
75
+ #outputs=[result, seed],
76
+ #cache_examples=True,
77
+ #cache_mode="lazy"
78
+ )
79
+
80
+ gr.on(
81
+ triggers=[run_button.click, prompt.submit],
82
+ fn=infer,
83
+ inputs=[prompt],
84
+ outputs=[result]
85
+ )
86
+ run_button2.click(infer2, [prompt], [result])
87
+
88
+ demo.launch(ssr_mode=False)
requirements.txt ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #torch==2.4.0+cu121
2
+ #torchvision
3
+ #torchaudio
4
+ torchao==0.9.0
5
+ git+https://github.com/huggingface/diffusers
6
+ peft
7
+ transformers
8
+ numpy<2
9
+ sentencepiece
10
+ protobuf
11
+ triton