Qwen3.5-4B-NLI-v5-SGLang
Model repository: savinirsekas/qwen3.5-4b-nli-v5-sglang
Inference engine: SGLang
Runtime image: lmsysorg/sglang:v0.5.21-runtime
Model family: Qwen3.5
Overview
Qwen3.5-4B-NLI-v5-SGLang provides a self-hosted inference setup for a Qwen3.5 4B model, using SGLang and a custom model implementation.
The same underlying model artifacts can be deployed in two serving configurations, depending on the required inference interface:
- Classification mode: launched with
--is-embedding, intended for the custom/classifyAPI. - Decision mode: launched without
--is-embedding, intended for the/v1/decisionAPI.
Features
- Self-hosted inference using Docker and NVIDIA GPUs.
- SGLang-based model serving.
- Local model directory mounting, without requiring a Hugging Face cache snapshot layout.
- Custom model implementation through
custom_llm. - Configurable GPU visibility, context length, and static memory fraction.
- Two intended inference interfaces: classification and decision serving.
Two serving modes
Mode A: Classification
This configuration starts SGLang with --is-embedding.
python3 -m sglang.launch_server \
--model-path /models/qwen3.5-4b-nli-v5-sglang/model \
--served-model-name qwen3.5-4b-nli-v5-sglang \
--host 0.0.0.0 \
--json-model-override-args '{"architectures":["Qwen3_5ForConditionalGeneration"]}' \
--mem-fraction-static 0.30 \
--context-length 25000 \
--is-embedding
Intended API: /classify
This mode is intended for classification requests handled by the corresponding custom implementation or API layer.
The --is-embedding flag selects an SGLang serving mode. It does not independently create a trained classification head or guarantee that /classify is available in an unmodified SGLang installation.
Mode B: Decision model
This configuration launches the same model without --is-embedding.
python3 -m sglang.launch_server \
--model-path /models/qwen3.5-4b-nli-v5-sglang/model \
--served-model-name qwen3.5-4b-nli-v5-sglang \
--host 0.0.0.0 \
--json-model-override-args '{"architectures":["Qwen3_5ForConditionalGeneration"]}' \
--mem-fraction-static 0.30 \
--context-length 25000
Intended API: /v1/decision
This mode is intended for decision-oriented inference through the relevant custom implementation or application layer.
A decision model can produce structured judgments or scores rather than free-form explanations. The exact decision semantics depend on how the model was trained and how the request is constructed and scored.
The /v1/decision route should not be assumed to be a built-in SGLang endpoint; it must be provided by the serving implementation or an API wrapper.
Requirements
- Linux host with Docker.
- NVIDIA GPU and compatible NVIDIA driver.
- NVIDIA Container Toolkit configured for Docker.
- SGLang runtime image
lmsysorg/sglang:v0.5.21-runtime. - Model weights and tokenizer files.
- The custom
custom_llmpackage and any required dependencies.
GPU memory requirements depend on the checkpoint, runtime, context length, concurrency, and other workloads. The example uses a static memory fraction of 0.30 and a context length of 25,000 tokens; these are configuration choices, not guarantees of minimum hardware requirements.
Directory structure
The following is an illustrative deployment layout:
deployment/
├── compose.yaml
└── model/
├── model/
│ ├── config.json
│ ├── model.safetensors
│ └── tokenizer files
└── custom_llm/
├── __init__.py
└── qwen3_5_seqcls.py
The directory must contain the files required by the actual checkpoint and custom implementation. Ensure custom_llm is importable inside the container.
The example commands mount the local model directory at:
/models/qwen3.5-4b-nli-v5-sglang
The model weights are then loaded from:
/models/qwen3.5-4b-nli-v5-sglang/model
Docker deployment
Create the Docker network if it does not already exist:
docker network create inference-net
Run the following commands from the directory containing the model/ directory.
Classification service
docker run -d \
--name qwen3.5-4b-nli-v5-classify \
--restart unless-stopped \
--network inference-net \
--ipc host \
--gpus all \
-p 30018:30000 \
-e CUDA_VISIBLE_DEVICES=0 \
-e NVIDIA_VISIBLE_DEVICES=0 \
-e PYTHONPATH=/models/qwen3.5-4b-nli-v5-sglang \
-e SGLANG_EXTERNAL_MODEL_PACKAGE=custom_llm \
-v "$(pwd)/model:/models/qwen3.5-4b-nli-v5-sglang:ro" \
lmsysorg/sglang:v0.5.21-runtime \
bash -c '
python3 -m sglang.launch_server \
--model-path /models/qwen3.5-4b-nli-v5-sglang/model \
--served-model-name qwen3.5-4b-nli-v5-sglang \
--host 0.0.0.0 \
--json-model-override-args '\''{"architectures":["Qwen3_5ForConditionalGeneration"]}'\'' \
--mem-fraction-static 0.30 \
--context-length 25000 \
--is-embedding
'
Decision service
docker run -d \
--name qwen3.5-4b-nli-v5-decision \
--restart unless-stopped \
--network inference-net \
--ipc host \
--gpus all \
-p 30017:30000 \
-e CUDA_VISIBLE_DEVICES=0 \
-e NVIDIA_VISIBLE_DEVICES=0 \
-e PYTHONPATH=/models/qwen3.5-4b-nli-v5-sglang \
-e SGLANG_EXTERNAL_MODEL_PACKAGE=custom_llm \
-v "$(pwd)/model:/models/qwen3.5-4b-nli-v5-sglang:ro" \
lmsysorg/sglang:v0.5.21-runtime \
bash -c '
python3 -m sglang.launch_server \
--model-path /models/qwen3.5-4b-nli-v5-sglang/model \
--served-model-name qwen3.5-4b-nli-v5-sglang \
--host 0.0.0.0 \
--json-model-override-args '\''{"architectures":["Qwen3_5ForConditionalGeneration"]}'\'' \
--mem-fraction-static 0.30 \
--context-length 25000
'
These commands demonstrate the two launch configurations. They do not install missing custom Python code or add application-specific HTTP routes automatically.
Verify the services
Inspect logs:
docker logs -f qwen3.5-4b-nli-v5-classify
docker logs -f qwen3.5-4b-nli-v5-decision
Check SGLang health:
curl -sS http://localhost:30018/health
curl -sS http://localhost:30017/health
A successful health check confirms server health, not that the custom classification or decision endpoint has been correctly registered.
API usage
The endpoint contracts depend on the custom implementation deployed with the model.
Classification API
The intended endpoint is:
POST /classify
Example request structure, to be adapted to the actual API schema:
{
"text": "The patient has a fever.",
"candidate_labels": [
"entailment",
"contradiction",
"neutral"
]
}
This is an illustrative payload, not a guaranteed request schema. Confirm the actual input fields and response format against the implementation before using this example.
Decision API
The intended endpoint is:
POST /v1/decision
The request should follow the schema implemented by the decision-serving layer. Decision APIs may evaluate a context and candidate choices and return structured scores or a selected result.
The precise request fields, scoring behavior, and output format must be documented from the deployed implementation. Do not assume that the classification request schema is interchangeable with the decision request schema.
Important API distinction
| Property | Classification mode | Decision mode |
|---|---|---|
| Launch configuration | Includes --is-embedding |
Omits --is-embedding |
| Intended endpoint | /classify |
/v1/decision |
| Serving behavior | Defined by the classification implementation | Defined by the decision implementation |
| Output interpretation | Depends on the classification contract | Depends on the decision/scoring contract |
The launch flag selects a serving configuration. It does not itself determine the model's learned task, establish the validity of NLI labels, or guarantee a particular scoring method.
Configuration reference
| Parameter | Value | Description |
|---|---|---|
| Runtime image | lmsysorg/sglang:v0.5.21-runtime |
SGLang container |
| Model directory | /models/qwen3.5-4b-nli-v5-sglang/model |
Model weights and configuration |
| Served model name | qwen3.5-4b-nli-v5-sglang |
API model identifier |
| Internal port | 30000 |
SGLang HTTP port |
| Classification host port | 30018 |
Example external port |
| Decision host port | 30017 |
Example external port |
| Static memory fraction | 0.30 |
SGLang memory configuration |
| Context length | 25000 |
Configured context length |
| Custom package | custom_llm |
Custom model implementation |
| Classification flag | --is-embedding |
Enables embedding-serving mode |
| Decision flag | Not specified | Launch without --is-embedding |
Troubleshooting
Model loading fails
Check that the model directory exists and contains the expected weights and configuration.
ls -la model/
ls -la model/model/
Verify that the mounted path matches --model-path.
Custom package cannot be imported
Check the Python path and package layout:
docker exec qwen3.5-4b-nli-v5-classify \
python3 -c 'import custom_llm; print(custom_llm.__file__)'
Repeat for the decision container if necessary.
CUDA is unavailable
nvidia-smi
docker exec qwen3.5-4b-nli-v5-classify nvidia-smi
Verify driver compatibility, NVIDIA Container Toolkit configuration, and GPU visibility.
The API endpoint returns 404
A healthy SGLang process does not guarantee that /classify or /v1/decision exists. Verify that the relevant router or custom endpoint is registered in the implementation.
GPU out-of-memory errors
Reduce context length or concurrency, adjust the memory allocation, or use a GPU with more available memory. If running both containers on one GPU, account for the combined memory use of both processes.
Limitations and responsible use
- The serving configuration does not establish the training dataset, fine-tuning procedure, or evaluation performance.
- NLI accuracy and label semantics must be evaluated using an appropriate held-out dataset.
- Classification and decision outputs are not necessarily interchangeable.
- The configured context length does not guarantee that every request can fit in available GPU memory.
- For clinical or other high-impact use cases, validate the model and maintain appropriate human oversight.
- Do not expose inference endpoints publicly without appropriate authentication, rate limiting, and network security.
savinirsekas/qwen3.5-4b-nli-v5-sglang
For reproducibility, record the model revision, SGLang image version, custom implementation revision, GPU configuration, and serving mode used for each experiment.