patrickvonplaten
commited on
Commit
•
a38f44b
1
Parent(s):
a9639c8
[LCM] Better error message
Browse files- + +21 -0
- bug_5776.py +7 -0
- clean.py +2 -0
- delete_function.py +38 -0
- os +0 -0
- run_lcm.py +21 -0
- run_randn.py +13 -0
- run_whisper.py +20 -0
- snow_mountain.png +0 -0
+
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
pipe = AutoPipelineForText2Image.from_pretrained("SimianLuo/LCM_Dreamshaper_v7", dtype=torch.float16)
|
6 |
+
|
7 |
+
prompt = "A beautiful landscape of a snowy mountain"
|
8 |
+
|
9 |
+
num_inference_steps = 1
|
10 |
+
|
11 |
+
image = pipe(prompt=prompt, num_inference_steps=num_inference_steps, output_type="pil").images[0]
|
12 |
+
image.save("snow_mountain.png")
|
13 |
+
|
14 |
+
pipe = AutoPipelineForImage2Image.from_pipe(pipe)
|
15 |
+
|
16 |
+
prompt = "A beautiful landscape of a very red mountain"
|
17 |
+
|
18 |
+
image = pipe(prompt=prompt, image=image, num_inference_steps=10, strength=0.05, output_type="pil").images[0]
|
19 |
+
image.show()
|
20 |
+
|
21 |
+
|
bug_5776.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
pipeline = AutoPipelineForText2Image.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16).to("cuda")
|
6 |
+
pipeline.load_lora_weights("ostris/super-cereal-sdxl-lora", weight_name="cereal_box_sdxl_v1.safetensors")
|
7 |
+
print(pipeline.unet.attn_processor)
|
clean.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import *
|
delete_function.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import sys
|
3 |
+
|
4 |
+
filenames = sys.argv[1:]
|
5 |
+
|
6 |
+
MATCH_PATTERN_1 = "# Copied from transformers.models.bart.modeling_bart._make_causal_mask"
|
7 |
+
MATCH_PATTERN_2 = "def _make_causal_mask("
|
8 |
+
|
9 |
+
MATCH_PATTERN_1 = "# Copied from transformers.models.bart.modeling_bart.prepare_4d_attention_mask"
|
10 |
+
MATCH_PATTERN_2 = "def prepare_4d_attention_mask(mask: torch.Tensor, dtype: torch.dtype, tgt_len: Optional[int] = None):"
|
11 |
+
|
12 |
+
END_MATCH_PATTERN_2 = ""
|
13 |
+
|
14 |
+
# MATCH_PATTERN_1 = "def _prepare_decoder_attention_mask(self, attention_mask, input_shape, inputs_embeds, past_key_values_length):"
|
15 |
+
#MATCH_PATTERN_2 = "# create causal mask"
|
16 |
+
|
17 |
+
# END_MATCH_PATTERN_2 = "def forward("
|
18 |
+
|
19 |
+
|
20 |
+
for filename in filenames:
|
21 |
+
with open(filename, "r") as f:
|
22 |
+
lines = f.readlines()
|
23 |
+
|
24 |
+
new_lines = []
|
25 |
+
is_in_del = False
|
26 |
+
for i, line in enumerate(lines):
|
27 |
+
if line.strip().lstrip() == MATCH_PATTERN_1 and i < len(lines) - 1 and lines[i + 1].strip().lstrip() == MATCH_PATTERN_2:
|
28 |
+
print("suh")
|
29 |
+
is_in_del = True
|
30 |
+
elif line.strip().lstrip() == "" and i < len(lines) - 1 and lines[i + 1].strip().lstrip() == END_MATCH_PATTERN_2:
|
31 |
+
is_in_del = False
|
32 |
+
|
33 |
+
if not is_in_del:
|
34 |
+
new_lines.append(line)
|
35 |
+
|
36 |
+
|
37 |
+
with open(filename, "w") as f:
|
38 |
+
f.writelines(new_lines)
|
os
ADDED
File without changes
|
run_lcm.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image
|
3 |
+
import torch
|
4 |
+
|
5 |
+
pipe = AutoPipelineForText2Image.from_pretrained("SimianLuo/LCM_Dreamshaper_v7", dtype=torch.float16)
|
6 |
+
|
7 |
+
prompt = "A beautiful landscape of a snowy mountain"
|
8 |
+
|
9 |
+
num_inference_steps = 1
|
10 |
+
|
11 |
+
image = pipe(prompt=prompt, num_inference_steps=num_inference_steps, output_type="pil").images[0]
|
12 |
+
image.save("snow_mountain.png")
|
13 |
+
|
14 |
+
pipe = AutoPipelineForImage2Image.from_pipe(pipe)
|
15 |
+
|
16 |
+
prompt = "A beautiful landscape of a very red mountain"
|
17 |
+
|
18 |
+
image = pipe(prompt=prompt, image=image, num_inference_steps=10, strength=0.05, output_type="pil").images[0]
|
19 |
+
image.show()
|
20 |
+
|
21 |
+
|
run_randn.py
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
|
4 |
+
def get_random():
|
5 |
+
return torch.randn((2,2))
|
6 |
+
|
7 |
+
seeds = []
|
8 |
+
for _ in range(5):
|
9 |
+
num = get_random()
|
10 |
+
seeds.append(torch.initial_seed())
|
11 |
+
print(num)
|
12 |
+
|
13 |
+
print("Seeds should be different, but are not", seeds)
|
run_whisper.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from transformers import WhisperForCausalLM, WhisperForConditionalGeneration, WhisperProcessor
|
3 |
+
import torch
|
4 |
+
from datasets import load_dataset
|
5 |
+
|
6 |
+
processor = WhisperProcessor.from_pretrained("openai/whisper-large-v2")
|
7 |
+
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large-v2")
|
8 |
+
|
9 |
+
assistant_model = WhisperForCausalLM.from_pretrained("patrickvonplaten/whisper-large-v2-32-2")
|
10 |
+
|
11 |
+
ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
12 |
+
sample = ds[0]["audio"]
|
13 |
+
input_features = processor(sample["array"], sampling_rate=sample["sampling_rate"], return_tensors="pt").input_features
|
14 |
+
|
15 |
+
predicted_ids = model.generate(input_features, assistant_model=assistant_model)
|
16 |
+
|
17 |
+
# decode token ids to text
|
18 |
+
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
19 |
+
|
20 |
+
print(transcription)
|
snow_mountain.png
ADDED