ThatDustyGuy's picture
Add files using upload-large-folder tool
c070c9d verified
metadata
license: other
base_model: black-forest-labs/FLUX.2-dev
tags:
  - flux2
  - flux2-diffusers
  - text-to-image
  - image-to-image
  - diffusers
  - simpletuner
  - not-for-all-audiences
  - lora
  - template:sd-lora
  - lycoris
pipeline_tag: text-to-image
inference: true
widget:
  - text: unconditional (blank prompt)
    parameters:
      negative_prompt: blurry, cropped, ugly
    output:
      url: ./assets/image_0_0.png

simpletuner

This is a LyCORIS adapter derived from black-forest-labs/FLUX.2-dev.

No validation prompt was used during training.

None

Validation settings

  • CFG: 7.5
  • CFG Rescale: 0.0
  • Steps: 30
  • Sampler: FlowMatchEulerDiscreteScheduler
  • Seed: None
  • Resolution: 256

Note: The validation settings are not necessarily the same as the training settings.

You can find some example images in the following gallery:

Prompt
DLAY man in a professional studio portrait with soft lighting, high quality photography, sharp focus
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man standing outdoors in natural sunlight, casual pose, candid photography style
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man in a formal business suit, professional headshot, corporate photography
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man in an artistic portrait with dramatic lighting and shadows, fine art photography
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man in a cinematic composition, film grain, moody atmosphere, dramatic lighting
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man in dynamic action pose, sports photography style, sharp motion capture
Negative Prompt
blurry, cropped, ugly
Prompt
DLAY man walking through a busy city street, urban photography, street style
Negative Prompt
blurry, cropped, ugly
Prompt
close up portrait of DLAY man, detailed face, professional lighting, 85mm lens
Negative Prompt
blurry, cropped, ugly

The text encoder was not trained. You may reuse the base model text encoder for inference.

Training settings

  • Training epochs: 0
  • Training steps: 5
  • Learning rate: 1.0
    • Learning rate schedule: constant
    • Warmup steps: 0
  • Max grad value: 2.0
  • Effective batch size: 1
    • Micro-batch size: 1
    • Gradient accumulation steps: 1
    • Number of GPUs: 1
  • Gradient checkpointing: False
  • Prediction type: flow_matching[]
  • Optimizer: prodigy (config=d_coef=2.0,weight_decay=0.01,use_bias_correction=False,schedulefree_c=75,use_orthograd=True)
  • Trainable parameter precision: Pure BF16
  • Base model precision: no_change
  • Caption dropout probability: 0.1%

LyCORIS Config:

{
    "algo": "lokr",
    "multiplier": 1.0,
    "factor": 12,
    "linear_dim": 100000,
    "linear_alpha": 1,
    "conv_dim": 0,
    "conv_alpha": 0,
    "dora_wd": true,
    "apply_preset": {
        "target_module": [
            "Flux2TransformerBlock",
            "Flux2SingleTransformerBlock"
        ]
    }
}

Datasets

dlay-subject-data

  • Repeats: 10
  • Total number of images: 269
  • Total number of aspect buckets: 1
  • Resolution: 1.048576 megapixels
  • Cropped: False
  • Crop style: None
  • Crop aspect: None
  • Used for regularisation data: No

Inference

import torch
from diffusers import DiffusionPipeline
from lycoris import create_lycoris_from_weights


def download_adapter(repo_id: str):
    import os
    from huggingface_hub import hf_hub_download
    adapter_filename = "pytorch_lora_weights.safetensors"
    cache_dir = os.environ.get('HF_PATH', os.path.expanduser('~/.cache/huggingface/hub/models'))
    cleaned_adapter_path = repo_id.replace("/", "_").replace("\\", "_").replace(":", "_")
    path_to_adapter = os.path.join(cache_dir, cleaned_adapter_path)
    path_to_adapter_file = os.path.join(path_to_adapter, adapter_filename)
    os.makedirs(path_to_adapter, exist_ok=True)
    hf_hub_download(
        repo_id=repo_id, filename=adapter_filename, local_dir=path_to_adapter
    )

    return path_to_adapter_file
    
model_id = 'black-forest-labs/FLUX.2-dev'
adapter_repo_id = 'simpletuner'
adapter_filename = 'pytorch_lora_weights.safetensors'
adapter_file_path = download_adapter(repo_id=adapter_repo_id)
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16) # loading directly in bf16
lora_scale = 1.0
wrapper, _ = create_lycoris_from_weights(lora_scale, adapter_file_path, pipeline.transformer)
wrapper.merge_to()

prompt = "An astronaut is riding a horse through the jungles of Thailand."
negative_prompt = 'blurry, cropped, ugly'

## Optional: quantise the model to save on vram.
## Note: The model was not quantised during training, so it is not necessary to quantise it during inference time.
#from optimum.quanto import quantize, freeze, qint8
#quantize(pipeline.transformer, weights=qint8)
#freeze(pipeline.transformer)
    
pipeline.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
model_output = pipeline(
    prompt=prompt,
    negative_prompt=negative_prompt,
    num_inference_steps=30,
    generator=torch.Generator(device='cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu').manual_seed(42),
    width=256,
    height=256,
    guidance_scale=7.5,
).images[0]

model_output.save("output.png", format="PNG")