Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
e487660
Add Photon model and pipeline support
Oct 8, 2025
6a66fbd
just store the T5Gemma encoder
Oct 9, 2025
d71ddd0
enhance_vae_properties if vae is provided only
Oct 9, 2025
14903ee
remove autocast for text encoder forwad
Oct 9, 2025
b327b36
BF16 example
david-PHR Oct 9, 2025
60d918d
conditioned CFG
Oct 10, 2025
6284b9d
remove enhance vae and use vae.config directly when possible
Oct 10, 2025
25a0061
move PhotonAttnProcessor2_0 in transformer_photon
Oct 10, 2025
5886925
remove einops dependency and now inherits from AttentionMixin
Oct 10, 2025
a9e3013
unify the structure of the forward block
Oct 10, 2025
b07d1c8
update doc
Oct 10, 2025
6634113
update doc
Oct 10, 2025
ec70e3f
fix T5Gemma loading from hub
Oct 10, 2025
12dbabe
fix timestep shift
Oct 13, 2025
ae44d84
remove lora support from doc
Oct 13, 2025
5f0bf01
Rename EmbedND for PhotoEmbedND
DavidBert Oct 13, 2025
af8882d
remove modulation dataclass
DavidBert Oct 13, 2025
3c60c92
put _attn_forward and _ffn_forward logic in PhotonBlock's forward
DavidBert Oct 13, 2025
de1ceaf
renam LastLayer for FinalLayer
DavidBert Oct 13, 2025
2077252
remove lora related code
DavidBert Oct 13, 2025
ffe3501
rename vae_spatial_compression_ratio for vae_scale_factor
DavidBert Oct 13, 2025
a74e0b7
support prompt_embeds in call
DavidBert Oct 13, 2025
c951ade
move xattention conditionning out computation out of the denoising loop
DavidBert Oct 13, 2025
be1d146
add negative prompts
DavidBert Oct 13, 2025
8ee17d2
Use _import_structure for lazy loading
DavidBert Oct 13, 2025
bb36735
make quality + style
DavidBert Oct 13, 2025
c329c8f
add pipeline test + corresponding fixes
DavidBert Oct 15, 2025
5f99168
utility function that determines the default resolution given the VAE
DavidBert Oct 15, 2025
0157743
Refactor PhotonAttention to match Flux pattern
DavidBert Oct 16, 2025
d0c029f
built-in RMSNorm
DavidBert Oct 16, 2025
6e05172
Revert accidental .gitignore change
DavidBert Oct 16, 2025
574f8fd
parameter names match the standard diffusers conventions
DavidBert Oct 16, 2025
0fdfd27
renaming and remove unecessary attributes setting
DavidBert Oct 16, 2025
34a7492
Update docs/source/en/api/pipelines/photon.md
DavidBert Oct 16, 2025
a8fa52b
quantization example
DavidBert Oct 16, 2025
9aa47ce
added doc to toctree
DavidBert Oct 16, 2025
c469a7a
Update docs/source/en/api/pipelines/photon.md
DavidBert Oct 16, 2025
caf6440
Update docs/source/en/api/pipelines/photon.md
DavidBert Oct 16, 2025
836cd12
Update docs/source/en/api/pipelines/photon.md
DavidBert Oct 16, 2025
0ef0dc6
use dispatch_attention_fn for multiple attention backend support
DavidBert Oct 17, 2025
7d12474
naming changes
DavidBert Oct 18, 2025
adeb45e
make fix copy
DavidBert Oct 20, 2025
d5ffd35
Update docs/source/en/api/pipelines/photon.md
DavidBert Oct 20, 2025
fdc8e34
Add PhotonTransformer2DModel to TYPE_CHECKING imports
DavidBert Oct 20, 2025
1354f45
make fix-copies
DavidBert Oct 20, 2025
aed1f19
Use Tuple instead of tuple
DavidBert Oct 21, 2025
9e8279e
restrict the version of transformers
DavidBert Oct 21, 2025
5c54baa
Update tests/pipelines/photon/test_pipeline_photon.py
DavidBert Oct 21, 2025
8de7b92
Update tests/pipelines/photon/test_pipeline_photon.py
DavidBert Oct 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@
title: PAG
- local: api/pipelines/paint_by_example
title: Paint by Example
- local: api/pipelines/photon
title: Photon
- local: api/pipelines/pixart
title: PixArt-α
- local: api/pipelines/pixart_sigma
Expand Down
131 changes: 131 additions & 0 deletions docs/source/en/api/pipelines/photon.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<!-- Copyright 2025 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. -->

# Photon


Photon generates high-quality images from text using a simplified MMDIT architecture where text tokens don't update through transformer blocks. It employs flow matching with discrete scheduling for efficient sampling and uses Google's T5Gemma-2B-2B-UL2 model for multi-language text encoding. The ~1.3B parameter transformer delivers fast inference without sacrificing quality. You can choose between Flux VAE (8x compression, 16 latent channels) for balanced quality and speed or DC-AE (32x compression, 32 latent channels) for latent compression and faster processing.

## Available models

Photon offers multiple variants with different VAE configurations, each optimized for specific resolutions. Base models excel with detailed prompts, capturing complex compositions and subtle details. Fine-tuned models trained on the [Alchemist dataset](https://huggingface.co/datasets/yandex/alchemist) improve aesthetic quality, especially with simpler prompts.


| Model | Resolution | Fine-tuned | Distilled | Description | Suggested prompts | Suggested parameters | Recommended dtype |
|:-----:|:-----------------:|:----------:|:----------:|:----------:|:----------:|:----------:|:----------:|
| [`Photoroom/photon-256-t2i`](https://huggingface.co/Photoroom/photon-256-t2i)| 256 | No | No | Base model pre-trained at 256 with Flux VAE|Works best with detailed prompts in natural language|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-256-t2i-sft`](https://huggingface.co/Photoroom/photon-256-t2i-sft)| 512 | Yes | No | Fine-tuned on the [Alchemist dataset](https://huggingface.co/datasets/yandex/alchemist) dataset with Flux VAE | Can handle less detailed prompts|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i`](https://huggingface.co/Photoroom/photon-512-t2i)| 512 | No | No | Base model pre-trained at 512 with Flux VAE |Works best with detailed prompts in natural language|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i-sft`](https://huggingface.co/Photoroom/photon-512-t2i-sft)| 512 | Yes | No | Fine-tuned on the [Alchemist dataset](https://huggingface.co/datasets/yandex/alchemist) dataset with Flux VAE | Can handle less detailed prompts in natural language|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i-sft-distilled`](https://huggingface.co/Photoroom/photon-512-t2i-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/photon-512-t2i-sft`](https://huggingface.co/Photoroom/photon-512-t2i-sft) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i-dc-ae`](https://huggingface.co/Photoroom/photon-512-t2i-dc-ae)| 512 | No | No | Base model pre-trained at 512 with [Deep Compression Autoencoder (DC-AE)](https://hanlab.mit.edu/projects/dc-ae)|Works best with detailed prompts in natural language|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i-dc-ae-sft`](https://huggingface.co/Photoroom/photon-512-t2i-dc-ae-sft)| 512 | Yes | No | Fine-tuned on the [Alchemist dataset](https://huggingface.co/datasets/yandex/alchemist) dataset with [Deep Compression Autoencoder (DC-AE)](https://hanlab.mit.edu/projects/dc-ae) | Can handle less detailed prompts in natural language|28 steps, cfg=5.0| `torch.bfloat16` |
| [`Photoroom/photon-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/photon-512-t2i-dc-ae-sft-distilled)| 512 | Yes | Yes | 8-step distilled model from [`Photoroom/photon-512-t2i-dc-ae-sft-distilled`](https://huggingface.co/Photoroom/photon-512-t2i-dc-ae-sft-distilled) | Can handle less detailed prompts in natural language|8 steps, cfg=1.0| `torch.bfloat16` |s

Refer to [this](https://huggingface.co/collections/Photoroom/photon-models-68e66254c202ebfab99ad38e) collection for more information.

## Loading the pipeline

Load the pipeline with [`~DiffusionPipeline.from_pretrained`].

```py
from diffusers.pipelines.photon import PhotonPipeline

# Load pipeline - VAE and text encoder will be loaded from HuggingFace
pipe = PhotonPipeline.from_pretrained("Photoroom/photon-512-t2i-sft", torch_dtype=torch.bfloat16)
pipe.to("cuda")

prompt = "A front-facing portrait of a lion the golden savanna at sunset."
image = pipe(prompt, num_inference_steps=28, guidance_scale=5.0).images[0]
image.save("photon_output.png")
```

### Manual Component Loading

Load components individually to customize the pipeline for instance to use quantized models.

```py
import torch
from diffusers.pipelines.photon import PhotonPipeline
from diffusers.models import AutoencoderKL, AutoencoderDC
from diffusers.models.transformers.transformer_photon import PhotonTransformer2DModel
from diffusers.schedulers import FlowMatchEulerDiscreteScheduler
from transformers import T5GemmaModel, GemmaTokenizerFast
from diffusers import BitsAndBytesConfig as DiffusersBitsAndBytesConfig
from transformers import BitsAndBytesConfig as BitsAndBytesConfig

quant_config = DiffusersBitsAndBytesConfig(load_in_8bit=True)
# Load transformer
transformer = PhotonTransformer2DModel.from_pretrained(
"checkpoints/photon-512-t2i-sft",
subfolder="transformer",
quantization_config=quant_config,
torch_dtype=torch.bfloat16,
)

# Load scheduler
scheduler = FlowMatchEulerDiscreteScheduler.from_pretrained(
"checkpoints/photon-512-t2i-sft", subfolder="scheduler"
)

# Load T5Gemma text encoder
t5gemma_model = T5GemmaModel.from_pretrained("google/t5gemma-2b-2b-ul2",
quantization_config=quant_config,
torch_dtype=torch.bfloat16)
text_encoder = t5gemma_model.encoder.to(dtype=torch.bfloat16)
tokenizer = GemmaTokenizerFast.from_pretrained("google/t5gemma-2b-2b-ul2")
tokenizer.model_max_length = 256

# Load VAE - choose either Flux VAE or DC-AE
# Flux VAE
vae = AutoencoderKL.from_pretrained("black-forest-labs/FLUX.1-dev",
subfolder="vae",
quantization_config=quant_config,
torch_dtype=torch.bfloat16)

pipe = PhotonPipeline(
transformer=transformer,
scheduler=scheduler,
text_encoder=text_encoder,
tokenizer=tokenizer,
vae=vae
)
pipe.to("cuda")
```


## Memory Optimization

For memory-constrained environments:

```py
import torch
from diffusers.pipelines.photon import PhotonPipeline

pipe = PhotonPipeline.from_pretrained("Photoroom/photon-512-t2i-sft", torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload() # Offload components to CPU when not in use

# Or use sequential CPU offload for even lower memory
pipe.enable_sequential_cpu_offload()
```

## PhotonPipeline

[[autodoc]] PhotonPipeline
- all
- __call__

## PhotonPipelineOutput

[[autodoc]] pipelines.photon.pipeline_output.PhotonPipelineOutput
Loading