Skip to content

examples: refactor diffusion generation#22590

Merged
am17an merged 2 commits intoggml-org:masterfrom
Sailaukan:diffusion-refactor
May 4, 2026
Merged

examples: refactor diffusion generation#22590
am17an merged 2 commits intoggml-org:masterfrom
Sailaukan:diffusion-refactor

Conversation

@Sailaukan
Copy link
Copy Markdown
Contributor

Overview

This PR refactors the diffusion example code by moving shared diffusion types and functions into diffusion.h and diffusion.cpp. The llama-diffusion-cli behavior is initially intended to stay unchanged. The CLI keeps the command-line handling, model/context setup, prompt handling, progress display, and output printing, while the reusable diffusion generation logic now lives in a separate module. This refactor separates the core diffusion generation logic into a reusable format, making it easier to integrate into new projects while maintaining full support for CLI usage

Additional information

No Python code or diffusion algorithm changes are included in this PR. This is intended to be a simple refactor preserving the initial behavior

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: AI assistance was used to plan an initial code move, but refactoring was done manually. I reviewed and verified everything by running llama-diffusion-cli with a local Dream GGUF model for a short 64-step generation using and building the CLI target successfully

@Sailaukan Sailaukan requested a review from am17an as a code owner May 1, 2026 21:09
Copy link
Copy Markdown
Contributor

@am17an am17an left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if stuff in examples is supposed to be create libs, but this refactor looks good to me from static code analysis. cc @CISC @ggerganov for approval

@CISC
Copy link
Copy Markdown
Member

CISC commented May 3, 2026

I'm not sure if stuff in examples is supposed to be create libs

I guess the question is if this is mature enough to be moved out of examples and into experimental API.

@Sailaukan
Copy link
Copy Markdown
Contributor Author

I'm not sure if stuff in examples is supposed to be create libs

I guess the question is if this is mature enough to be moved out of examples and into experimental API.

I’ve actually built an API based on llama.cpp for diffusion models and this refactoring is just a small part of the work I’ve done

If you support the idea of creating an experimental API for diffusion LLMs, I will finish the implementation and submit a PR for review

Copy link
Copy Markdown
Member

@ggerganov ggerganov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's OK to have common functionality extracted into libraries in examples and reused. These libs can't be used directly by 3rd party projects. When the lib matures enough, it can potentially become part of the public API and be used by 3rd party projects.

Comment on lines +6 to +14

enum diffusion_algorithm { ORIGIN = 0, ENTROPY_BASED = 1, MARGIN_BASED = 2, RANDOM = 3, CONFIDENCE_BASED = 4 };

// Unified transfer scheduling methods
enum transfer_schedule {
TIMESTEP_BASED = 0, // Dream-style: (1.0 - s/t) * remaining
BLOCK_BASED = 1, // LLaDA-style: process in blocks with get_num_transfer_tokens
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The enums should be named appropriately - see the CONTRIBUTING.md for guidelines.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Renamed following the guideline

@Sailaukan Sailaukan requested a review from a team as a code owner May 3, 2026 18:10
@am17an am17an merged commit d8794ee into ggml-org:master May 4, 2026
42 of 46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants