Custom Logits Processing
NIM LLM 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 logits 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. However, you can toggle behavior per request by having clients pass custom arguments in vllm_xargs. Your processor checks each row’s extra_args and modifies only the rows that opt in. Each row in the tensor corresponds to one request.
Run a Custom Logits Processor
To run a custom logits processor, complete the following steps:
-
Place your processor script in a local directory.
-
Volume-mount that directory into the container.
-
Pass the processor’s module path to NIM by using the
--logits-processorsCLI argument:
The --logits-processors value uses Python’s module.submodule:ClassName format. The code must be importable from PYTHONPATH.
Write a Custom Logits Processor
Custom processors extend vllm.v1.sample.logits_processor.LogitsProcessor and implement the following five methods:
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.
Per-Request Toggling
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.