Custom Logits Processing
NIM LLM and VLM supports custom logits processing by passing through to vLLM’s native logits processor API. You can write your own processor, mount it into the container as a volume, and enable it with a single CLI flag.
Custom processors operate at the batch level. vLLM batches multiple requests into a single tensor for GPU efficiency, so your processor receives the entire batch together. Each row in the tensor is one request.
You can still toggle behavior per request. Clients pass custom arguments in vllm_xargs. Your processor reads each row’s extra_args and modifies only the rows that opt in.
Before you start, complete the following prerequisites:
- Write a processor that extends
vllm.v1.sample.logits_processor.LogitsProcessor, or use the example in this procedure. - Confirm that the processor module is importable from the
PYTHONPATHyou will set on the container.
To run a custom logits processor, complete the following steps:
-
Implement the five
LogitsProcessormethods in your processor script.Custom processors extend
vllm.v1.sample.logits_processor.LogitsProcessor. The following table describes each method:Example: BanTokenProcessor
The following processor bans a single token per request. Requests opt in by sending
{"vllm_xargs": {"ban_token_id": <int>}}. Requests that do not send this parameter are unaffected. -
Place your processor script in a local directory, for example
/home/user/my_processors/ban_token.py. -
Volume-mount that directory into the container.
-
Pass the processor’s module path to NIM by using the
--logits-processorsCLI argument.The
--logits-processorsvalue uses Python’smodule.submodule:ClassNameformat. The code must be importable fromPYTHONPATH. -
Optional: Enable the processor for a specific request by passing custom arguments in
vllm_xargs.Custom logits processors operate at the batch level, but clients can enable specific logits processors per request by passing custom arguments using
vllm_xargs.For more details on invoking custom logits processors per request, refer to the vLLM documentation.
Next Steps
After the processor loads, continue with Custom Parsers and Chat Templates if you also need a custom tool-call or reasoning parser.