Text Generation
Transformers
Safetensors
English
diffusion-gemma
block-diffusion
mixture-of-experts
Mixture of Experts
tinystories
tiny-model
validation
debug-model
Instructions to use shibatch/tinydiffusiongemmamoe4m with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use shibatch/tinydiffusiongemmamoe4m with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="shibatch/tinydiffusiongemmamoe4m")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("shibatch/tinydiffusiongemmamoe4m", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use shibatch/tinydiffusiongemmamoe4m with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "shibatch/tinydiffusiongemmamoe4m" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/shibatch/tinydiffusiongemmamoe4m
- SGLang
How to use shibatch/tinydiffusiongemmamoe4m with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "shibatch/tinydiffusiongemmamoe4m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "shibatch/tinydiffusiongemmamoe4m" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "shibatch/tinydiffusiongemmamoe4m", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use shibatch/tinydiffusiongemmamoe4m with Docker Model Runner:
docker model run hf.co/shibatch/tinydiffusiongemmamoe4m
File size: 1,694 Bytes
d657346 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import torch
from transformers import (
DiffusionGemmaForBlockDiffusion,
DiffusionGemmaGenerationConfig,
EntropyBoundSamplerConfig,
PreTrainedTokenizerFast,
)
MODEL_PATH = "."
MODEL_SUBFOLDER = "hf"
PROMPT = "Once upon"
def main() -> None:
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
tokenizer = PreTrainedTokenizerFast.from_pretrained(
MODEL_PATH,
subfolder=MODEL_SUBFOLDER,
)
model = DiffusionGemmaForBlockDiffusion.from_pretrained(
MODEL_PATH,
subfolder=MODEL_SUBFOLDER,
dtype=torch.float32,
).to(device)
model.eval()
generation_config = DiffusionGemmaGenerationConfig(
max_new_tokens=64,
max_denoising_steps=64,
sampler_config=EntropyBoundSamplerConfig(entropy_bound=1.0),
t_min=0.4,
t_max=0.8,
stability_threshold=3,
confidence_threshold=0.05,
bos_token_id=tokenizer.bos_token_id,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
cache_implementation="dynamic",
return_dict_in_generate=True,
)
input_ids = torch.tensor(
[
[tokenizer.bos_token_id]
+ tokenizer.encode(PROMPT, add_special_tokens=False)
],
dtype=torch.long,
device=device,
)
with torch.no_grad():
output = model.generate(
input_ids=input_ids,
generation_config=generation_config,
)
sequences = output.sequences if hasattr(output, "sequences") else output
print(tokenizer.decode(sequences[0].tolist(), skip_special_tokens=True))
if __name__ == "__main__":
main()
|