Views
No views yet
A peaceful Japanese-inspired scene unfolds, showcasing a cozy retreat nestled in the heart of nature. Towering mountains rise in the distance, framing a serene environment filled with vibrant plants and lush greenery. A calm pond reflects the bright sunlight, its surface adorned with delicate ripples and blooming lotus flowers\u2014where Frog basks on a lily pad, quietly observing the tranquil surroundings. Nearby, a rose garden adds a touch of romance, its soft petals contrasting beautifully with the earthy tones of the environment. Inside the rustic cottage, m0n1t0rs sitting in calm wearing headphones, adding a hint of nostalgic charm that complements the timeless beauty outside. This setting exudes tranquility, inviting you to pause, breathe, and connect with the harmony of nature\u2014a perfect haven where the natural splendor of Japan landscapes meets cozy serenity.3.00.020FlowMatchEulerDiscreteScheduler421344x7681{
2 "algo": "loha",
3 "multiplier": 1.0,
4 "linear_dim": 16,
5 "linear_alpha": 16,
6 "apply_preset": {
7 "target_module": [
8 "Attention",
9 "FeedForward"
10 ],
11 "module_algo_map": {
12 "Attention": {
13 "factor": 16
14 },
15 "FeedForward": {
16 "factor": 8
17 }
18 }
19 }
20}1import torch
2from diffusers import DiffusionPipeline
3from lycoris import create_lycoris_from_weights
4
5
6def download_adapter(repo_id: str):
7 import os
8 from huggingface_hub import hf_hub_download
9 adapter_filename = "pytorch_lora_weights.safetensors"
10 cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
11 cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
12 path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
13 path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
14 os.makedirs(path_to_adapter, exist_ok=True)
15 hf_hub_download(
16 repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
17 )
18
19 return path_to_adapter_file
20
21model_id = 'black-forest-labs/FLUX.1-dev'
22adapter_repo_id = 'maver1chh/cha2102_loha'
23adapter_filename = 'pytorch_lora_weights.safetensors'
24adapter_file_path = download_adapter(repo_id=adapter_repo_id)
25pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
26lora_scale = 1.0
27wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
28wrapper.merge_to()
29
30prompt = "A peaceful Japanese-inspired scene unfolds, showcasing a cozy retreat nestled in the heart of nature. Towering mountains rise in the distance, framing a serene environment filled with vibrant plants and lush greenery. A calm pond reflects the bright sunlight, its surface adorned with delicate ripples and blooming lotus flowers\u2014where Frog basks on a lily pad, quietly observing the tranquil surroundings. Nearby, a rose garden adds a touch of romance, its soft petals contrasting beautifully with the earthy tones of the environment. Inside the rustic cottage, m0n1t0rs sitting in calm wearing headphones, adding a hint of nostalgic charm that complements the timeless beauty outside. This setting exudes tranquility, inviting you to pause, breathe, and connect with the harmony of nature\u2014a perfect haven where the natural splendor of Japan landscapes meets cozy serenity."
31
32
33## Optional: quantise the model to save on vram.
34## Note: The model was quantised during training, and so it is recommended to do the same during inference time.
35from optimum.quanto import quantize, freeze, qint8
36quantize(pipeline.transformer, weights=qint8)
37freeze(pipeline.transformer)
38
39pipeline.to('cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu') # the pipeline is already in its target precision level
40image = pipeline(
41 prompt=prompt,
42 num_inference_steps=20,
43 generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
44 width=1344,
45 height=768,
46 guidance_scale=3.0,
47).images[0]
48image.save("output.png", format="PNG")