Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Hugging Face 10 min read How-to mediumAdept

Controlling Language Model Generation with NVIDIA's LogitsProcessorZoo

NVIDIA's LogitsProcessorZoo is a library of modular logits processors that plug into Hugging Face Transformers' `generate` method. They control LLM output by modifying token scores before sampling. Code examples on Llama-3.2-1B show four of them: GenLengthLogitsProcessor shortens or lengthens responses by adjusting the EOS token's likelihood, CiteFromPromptLogitsProcessor boosts prompt tokens to keep answers grounded, ForceLastPhraseLogitsProcessor inserts a fixed phrase before generation ends, and MultipleChoiceLogitsProcessor restricts output to one of the given choices. The post also briefly covers what logits are and why raw logits fall short for constrained generation tasks.

Assumes: Hugging Face TransformersLLM token samplingPyTorch basics

Related posts

  • Assisted Generation: a new direction toward low-latency text generation

    Hugging Face mediumAdept

    Assisted generation cuts autoregressive LLM latency by letting a much smaller assistant model with the same tokenizer greedily draft candidate tokens, then verifying them all in a single forward pass of the large model. The large model keeps matching tokens plus the first divergent one. The draft length adapts: it grows by 2 when every candidate matches and shrinks by 1 otherwise. The approach exploits the fact that forward passes are memory-bandwidth bound. In 🤗 Transformers it is exposed through an `assistant_model` argument to `generate` (batch size 1 only) and yields up to 2x speedups, 3x with INT8, and up to 10x when the model relies on memory offloading. It works best on input-grounded tasks like ASR and summarization, and with sampling only at low temperatures.

  • Preference Optimization for Vision Language Models

    Hugging Face hardMaster

    TRL now supports direct preference optimization (DPO) for vision language models, trained on chosen/rejected answer pairs rather than fixed labels. A walkthrough fine-tunes Idefics2-8b on the RLAIF-V dataset, formatting image-plus-question prompts with the processor's chat template. Full float32 DPO training would need about 160 GB (policy, reference model, gradients, AdamW states), but bfloat16 plus LoRA cuts trainable parameters to 55M and memory to roughly 32 GB. Batch size 2 with 32 gradient accumulation steps and gradient checkpointing fits activations, and training is judged by rising accuracy and reward margin.

  • Promptim: an experimental library for prompt optimization

    LangChain easyNovice

    Promptim is an open-source, experimental library that automates prompt engineering: given an initial prompt, a LangSmith dataset and custom evaluators, it runs an optimization loop where a metaprompt proposes edits based on scored train-set results, and keeps a new prompt only if it improves dev-split metrics, repeated N times. Optional human feedback via LangSmith annotation queues covers cases without good automated metrics. Unlike DSPy, which optimizes whole compound AI systems and includes fine-tuning and few-shot methods, Promptim focuses narrowly on rewriting a single prompt with a human kept in the loop.

  • Productizing Large Language Models

    Replit mediumAdept

    Replit runs transformer models from ~100M parameters (search, spam) through 1-10B (GhostWriter code autocomplete) to 100B+ in production, and shares lessons on making them usable. Nonsense and repetition loops are handled with temperature and frequency penalty tuning, cycle detection, multi-temperature sampling, reranking with a second model, and fine-tuning on user feedback. Quality is tracked with HumanEval, loop and nonsense rates, and A/B tests. Inference cost is cut with FasterTransformer, distillation and quantization, and GPUs are run at 70-80% utilization on Kubernetes so request queues stay bounded while autoscaling has headroom.

  • Welcome Mixtral - a SOTA Mixture of Experts on Hugging Face

    Hugging Face mediumAdept

    Mixtral 8x7B is Mistral's sparse Mixture-of-Experts LLM. It replaces feed-forward layers with MoE layers that route each token to 2 of 8 experts, so it has about 45B total parameters but decodes at roughly the speed of a 12B dense model. On release it beat Llama 2 70B on the Open LLM Leaderboard and matched GPT-3.5 on MT-Bench (8.30), under an Apache 2.0 license. Hugging Face shipped integrations for running it with Transformers and Text Generation Inference, plus QLoRA fine-tuning with TRL on one A100 (attention projections only, since sparse MLP layers interact poorly with PEFT). For quantization, VRAM needs are about 90 GB in fp16 and about 23 GB in 4-bit, and GPTQ performs better when the expert gating layers are left unquantized (perplexity 4.40 vs 4.25 in fp16).

The quest for software engineering knowledge.

Look:
Layout: