Add files for diffusers loading

#20
by dg845 - opened

Pull Request opened with the huggingface_hub Python library

dg845 changed pull request title from Add diffusers scheduler for diffusers loading to Add files for diffusers loading

This PR adds a diffusers scheduler/ subdirectory and model_index.json file to support diffusers loading. After the PR, the following should work:

import torch
from diffusers import DiffusionGemmaPipeline

model_id = "google/diffusiongemma-26B-A4B-it"
pipe = DiffusionGemmaPipeline.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    revision="refs/pr/20",   # Omit if merged to main
)
pipe.to("cuda")

output = pipe(
    prompt="Why is the sky blue?",
    gen_length=256,
    num_inference_steps=48,
    cache_implementation="static",
    generator=torch.Generator("cuda").manual_seed(42),
)
print(output.texts[0])

I think there may be a bug where using only DiffusionGemmaPipeline.from_pretrained doesn't correctly get all of the modeling files. For now, this can be mitigated by first using snapshot_download to get all of the files:

import torch
from huggingface_hub import snapshot_download
from diffusers import DiffusionGemmaPipeline

model_id = "google/diffusiongemma-26B-A4B-it"
snapshot_download(repo_id=model_id, revision="refs/pr/20")

pipe = DiffusionGemmaPipeline.from_pretrained(
    model_id,
    torch_dtype=torch.bfloat16,
    revision="refs/pr/20",   # Omit if merged to main
)
pipe.to("cuda")

output = pipe(
    prompt="Why is the sky blue?",
    gen_length=256,
    num_inference_steps=48,
    cache_implementation="static",
    generator=torch.Generator("cuda").manual_seed(42),
)
print(output.texts[0])

Closing the PR for now, we will re-open once we have addressed the issue described in https://huggingface.co/google/diffusiongemma-26B-A4B-it/discussions/20#6a43020c48cb38f28686f686.

dg845 changed pull request status to closed
dg845 changed pull request status to open

Reopening the PR. After this diffusers PR, the issue should be addressed and from_pretrained should work as expected without first needing a snapshot_download.

Ready to merge
This branch is ready to get merged automatically.

Sign up or log in to comment