Instructions to use akshan-main/tiny-diffusion-gemma-modular-pipe with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use akshan-main/tiny-diffusion-gemma-modular-pipe with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("akshan-main/tiny-diffusion-gemma-modular-pipe", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Draw Things
- DiffusionBee
This is a modular diffusion pipeline built with 🧨 Diffusers' modular pipeline framework.
Pipeline Type: DiffusionGemmaBlocks
Description: Modular blocks for DiffusionGemma block-diffusion text generation.
text_encoderapplies the chat template and tokenizes the promptprepare_generationsizes the canvases, creates the KV cache and resolves EOSset_timestepssplits the forward budget and configures the schedulerdenoisegenerates the text canvas by canvasdecodetrims at EOS and decodes the token IDs into text
This pipeline uses a 5-block architecture that can be customized and extended.
Example Usage
[TODO]
Pipeline Architecture
This modular pipeline is composed of the following blocks:
- text_encoder (
DiffusionGemmaTextEncoderStep)- Text encoder step that applies the chat template to a
promptor a rawmessagesconversation and tokenizes it into the prompt token IDs consumed by the encoder prefill
- Text encoder step that applies the chat template to a
- prepare_generation (
DiffusionGemmaPrepareGenerationStep)- Prepare step that sizes the generation into canvases, creates the encoder KV cache, and resolves the EOS token used for early stopping and trimming
- set_timesteps (
DiffusionGemmaSetTimestepsStep)- Step that splits the per-canvas forward budget into predictor and corrector steps and configures the scheduler's refinement schedule
- denoise (
DiffusionGemmaDenoiseStep)- Canvas denoise step that iterates over canvases.
- decode (
DiffusionGemmaDecodeStep)- Decode step that trims each generated sequence at its first EOS token and decodes the token IDs into text with the processor
Model Components
- processor (
ProcessorMixin) - model (
DiffusionGemmaForBlockDiffusion) - scheduler (
BlockRefinementScheduler)
Input/Output Specification
Inputs:
prompt(str, optional): Prompt text, wrapped in a chat template and tokenizedmessages(list, optional): A raw chat conversation to encode instead ofprompt, e.g.[{"role": "user", "content": "Hello"}]or a multi-turn / multimodal conversation.image(Image | ndarray | Tensor | list | list | list, optional): Image(s) to pair withpromptfor multimodal generation. For richer layouts, put the image content directly inmessages.add_generation_prompt(bool, optional, defaults toTrue): Whether to add the generation prompt when applying the chat template.gen_length(int, optional, defaults to256): Number of tokens to generate, rounded up to a multiple of the model'scanvas_length.cache_implementation(str, optional): Set to"static"to use a fixed-shapeStaticCacheso the decoder can be compiled.eos_token_id(int, optional): EOS token ID for early stopping. Falls back to the processor's tokenizer.num_inference_steps(int, optional, defaults to48): Number of denoising steps per canvas, i.e. the per-canvas budget of model forwards.eos_early_stop(bool, optional, defaults toTrue): Whether to stop generating further canvases once every sequence has emitted EOS.generator(Generator, optional): Torch generator for deterministic generation.temperature(float, optional, defaults to0.0): Sampling temperature (0.0is greedy). Other sampling knobs are scheduler config.stability_threshold(int, optional, defaults to1): Consecutive steps the argmax prediction must be unchanged for a canvas to count as stable. Only used whenconfidence_thresholdis set.confidence_threshold(float, optional, defaults to0.005): Leave the refinement loop early once every example is stable and the mean per-token entropy is below this value. Set toNoneto always run all steps.
Outputs:
prompt_ids(LongTensor): Tokenized prompt of shape(batch_size, prompt_length).prompt_attention_mask(LongTensor): Attention mask forprompt_ids.multimodal_inputs(dict): Image tensors the processor produced for the encoder prefill.canvas_length(int): The model's canvas length, i.e. the number of tokens denoised per block.num_canvases(int): Number of canvases to generate.past_key_values(object): The encoder KV cache reused across canvases and denoising steps.eos_token_id(int): The resolved EOS token ID (user-provided or from the processor's tokenizer).finished(Tensor): Per-example flags marking sequences that already emitted EOS.predictor_steps(int): Predictor steps run per canvas.corrected_steps(int): Number of leading predictor steps that also run corrector sweeps.corrector_steps(int): Corrector sweeps run after each of the firstcorrected_stepspredictor steps.decoder_position_ids(LongTensor): Position IDs of the canvas tokens, continuing the running sequence.decoder_attention_mask_mapping(object): The decoder attention mask mapping built over the populated cache plus the canvas.canvas(LongTensor): The noisy canvas of shape(batch_size, canvas_length)being denoised.sequences(LongTensor): The generated token IDs of shape(batch_size, generated_length).texts(list): The decoded generated text, one string per prompt.
- Downloads last month
- 11