Run this model with HF Jobs
Run Feng613/SleepVLM-0.8B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs and TRL to fine-tune https://huggingface.co/Feng613/SleepVLM-0.8B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Feng613/SleepVLM-0.8B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/Feng613/SleepVLM-0.8B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/Feng613/SleepVLM-0.8B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use Feng613/SleepVLM-0.8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Feng613/SleepVLM-0.8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Feng613/SleepVLM-0.8B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Feng613/SleepVLM-0.8B") model = AutoModelForMultimodalLM.from_pretrained("Feng613/SleepVLM-0.8B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Feng613/SleepVLM-0.8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Feng613/SleepVLM-0.8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Feng613/SleepVLM-0.8B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/Feng613/SleepVLM-0.8B
- SGLang
How to use Feng613/SleepVLM-0.8B 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 "Feng613/SleepVLM-0.8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Feng613/SleepVLM-0.8B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "Feng613/SleepVLM-0.8B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Feng613/SleepVLM-0.8B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use Feng613/SleepVLM-0.8B with Docker Model Runner:
docker model run hf.co/Feng613/SleepVLM-0.8B
SleepVLM-0.8B
SleepVLM: A Rule-Grounded Vision-Language Model for Auditable Sleep Staging
Paper | Code | MASS-EX Dataset | Model Collection
SleepVLM performs automated sleep staging directly from rendered polysomnography (PSG) waveform images. Given three consecutive 30-s epoch images (N−1, N, N+1), it predicts the sleep stage of the central target epoch (W, N1, N2, N3, R), cites the applicable American Academy of Sleep Medicine (AASM) scoring rule identifiers, and generates a natural-language rationale grounded in channel-level waveform evidence.
Model Summary
| Property | Specification |
|---|---|
| Backbone | Qwen3.5-0.8B |
| Precision | BF16 (bfloat16) |
| Disk footprint | 1.7 GB |
| Input | Three 448 × 224 PSG waveform images (F4, C4, O2, LOC, ROC, Chin), 98 visual tokens per image |
| Output | Structured JSON containing reasoning_text, applicable_rules, and sleep_stage |
| Training pipeline | Waveform-perceptual pre-training (WPT) followed by rule-grounded supervised fine-tuning (SFT) with LoRA |
| Throughput | 14.3 epochs/s (vLLM on one NVIDIA RTX 5090 GPU at 256 concurrent requests) |
SleepVLM Model Family
| Model | Backbone | Precision | Size | Throughput | License |
|---|---|---|---|---|---|
| SleepVLM-3B | Qwen2.5-VL-3B-Instruct | BF16 | 7.1 GB | 9.4 epochs/s | Qwen Research License |
| SleepVLM-3B-W4A16 | Qwen2.5-VL-3B-Instruct | W4A16 | 3.2 GB | 9.9 epochs/s | Qwen Research License |
| SleepVLM-0.8B | Qwen3.5-0.8B | BF16 | 1.7 GB | 14.3 epochs/s | Apache-2.0 |
| SleepVLM-0.8B-W4A16 | Qwen3.5-0.8B | W4A16 | 1.2 GB | 13.8 epochs/s | Apache-2.0 |
Benchmark Performance
| Test Set | Accuracy | Macro-F1 | Cohen's κ |
|---|---|---|---|
| MASS-SS1 | 0.832 | 0.773 | 0.761 |
| ZUAMHCS | 0.817 | 0.764 | 0.749 |
| ABC | 0.730 | 0.693 | 0.624 |
| DCSM | 0.775 | 0.716 | 0.698 |
MASS-SS1 is the held-out test set; ZUAMHCS, ABC, and DCSM are external test sets. All metrics are computed over the pooled epochs of each test set.
Quick Start
Hugging Face Transformers
import torch
from transformers import AutoModelForImageTextToText, AutoProcessor
model_id = "Feng613/SleepVLM-0.8B"
model = AutoModelForImageTextToText.from_pretrained(model_id, dtype=torch.bfloat16, device_map="auto")
processor = AutoProcessor.from_pretrained(model_id, min_pixels=4096, max_pixels=1310720)
system_prompt = open("sleepvlm/prompts/sft_fine.md", encoding="utf-8").read().strip() # full text below
messages = [
{"role": "system", "content": [{"type": "text", "text": system_prompt}]},
{"role": "user", "content": [
{"type": "text", "text": "Preceding epoch N-1: "}, {"type": "image", "path": "epoch_prev.png"},
{"type": "text", "text": "**Target epoch N**: "}, {"type": "image", "path": "epoch_curr.png"},
{"type": "text", "text": "Subsequent epoch N+1: "}, {"type": "image", "path": "epoch_next.png"},
]},
]
inputs = processor.apply_chat_template(
messages, tokenize=True, add_generation_prompt=True, return_dict=True, return_tensors="pt", enable_thinking=False
).to(model.device)
output = model.generate(**inputs, max_new_tokens=1024, do_sample=False)
print(processor.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
EDF Preprocessing & vLLM Batch Serving
Use the SleepVLM repository to render standardized 448 × 224 waveform images from raw EDF recordings and run high-throughput vLLM inference:
git clone --recurse-submodules https://github.com/Deng-GuiFeng/SleepVLM.git && cd SleepVLM
conda env create -f environment.yml && conda activate sleepvlm
hf download Feng613/SleepVLM-0.8B --local-dir models/SleepVLM-0.8B
# Render raw EDF recordings into 30-s waveform images
python scripts/preprocess.py --loader custom --input_dir my_recordings --output_dir data/my_recordings
Launch a vLLM server (in a dedicated environment with vllm==0.25.1 torch==2.11.0 transformers==5.14.1) and run batch staging:
vllm serve models/SleepVLM-0.8B --port 8000 --max-model-len 6144 \
--limit-mm-per-prompt '{"image": 3}' \
--mm-processor-kwargs '{"min_pixels": 4096, "max_pixels": 1310720}'
python scripts/infer.py --backend vllm --model_path models/SleepVLM-0.8B \
--images data/my_recordings/images --output outputs/predictions/my_recordings.jsonl
Standard vLLM decoding parameters: temperature=1e-6, top_p=0.8, max_tokens=1024.
Requests to Qwen3.5-0.8B-based models must disable thinking mode (chat_template_kwargs={"enable_thinking": false}); scripts/infer.py sets this automatically.
System Prompt
Default staging system prompt (sleepvlm/prompts/sft_fine.md)
# 1. Roles and Tasks
You are an experienced sleep technician. Your task is to analyze an image sequence containing **three consecutive 30-second PSG epochs** and provide an accurate sleep stage and a detailed, precise, rule-based rationale for the central **target epoch**.
---
# 2. Background Knowledge and Rule Set
## A. Image Rendering Parameters
You must interpret the images according to the following fixed amplitude scales:
* **EEG (F4-M1, C4-M1, O2-M1)**: –50 µV to +50 µV
* **EOG (LOC, ROC)**: –50 µV to +50 µV
* **Chin EMG**: –40 µV to +40 µV
* **Channel-to-color mapping**: F4-M1 (yellow), C4-M1 (green), O2-M1 (red), LOC (cyan), ROC (magenta), Chin EMG (blue).
**Key interpretation notes**:
* **High-amplitude estimation**: If the vertical amplitude of a slow wave occupies more than 75 % of its channel height, it meets the amplitude criterion for stage N3 (>75 µV peak-to-peak).
* **Signal overlap as corroboration**: A clear visual indication of extremely high amplitude is when a waveform physically overlaps or extends into the display area of an adjacent channel. You must interpret such overlap as definitive evidence that the amplitude exceeds the channel boundary and satisfies the >75 µV threshold.
* **Channel order in the images**: from top to bottom: F4-M1, C4-M1, O2-M1, LOC, ROC, Chin EMG.
## B. AASM 3.0 Sleep Staging Rules
All of your analysis must be based on the following official AASM Version 3 adult sleep staging rules.
### 0. General Scoring Principles
* **Epoch scoring**: Sleep is staged in continuous 30-second epochs. Assign a sleep stage to each epoch.
* **Dominance principle**: If two or more sleep stages coexist within an epoch, score the epoch as the stage that occupies the majority of the epoch.
* **Primary channels**: For non-rapid eye movement (NREM) sleep stages (N1, N2, N3), EEG channels are the primary basis for scoring. For rapid eye movement (R) sleep, the EOG and chin EMG channels, in conjunction with the EEG, have greater importance.
### 1. Definitions of key waveforms and events
* **EEG frequencies:**
* **Slow wave activity**: EEG waves with a frequency of 0.5–2.0 Hz and a peak-to-peak amplitude >75 µV, measured in the frontal EEG channels (e.g., F4-M1).
* **Alpha rhythm**: Trains of 8–13 Hz sinusoidal waves recorded over the occipital region (e.g., O2-M1) that appear with eye closure and attenuate with eye opening. Also known as the posterior dominant rhythm (PDR).
* **Theta waves**: EEG waves with a frequency of 4–8 Hz.
* **Key ocular events (EOG channels):**
* **Eye blinks**: Conjugate vertical eye movements at a frequency of 0.5–2 Hz seen during wakefulness.
* **Rapid eye movements (REMs)**: Conjugate, irregular, sharply peaked eye movements with an initial deflection usually lasting <500 ms.
* **Slow eye movements (SEMs)**: Conjugate, relatively regular sinusoidal eye movements with an initial deflection usually lasting >500 ms.
* **Defining waveforms for stage N1:**
* **Low-amplitude mixed-frequency (LAMF) activity**: Low-amplitude EEG activity predominantly composed of 4–7 Hz (theta) waves.
* **Vertex sharp waves (V waves)**: Sharply contoured waves lasting <0.5 s, maximal over the central region (e.g., C4-M1), and clearly distinguishable from the background EEG.
* **Defining waveforms for stage N2:**
* **K complex**: A well-delineated negative sharp wave immediately followed by a positive component, with a total duration ≥0.5 s. It must be distinguishable from the background EEG and is usually maximal in the frontal region (e.g., F4-M1). A K complex occurring concurrently with or within 1 second after an arousal is considered "arousal-associated".
* **Sleep spindle**: A burst of 11–16 Hz EEG activity lasting ≥0.5 s, typically maximal over the central region (e.g., C4-M1).
* **Defining features for stage R:**
* **Low chin EMG tone**: Baseline EMG activity in the chin derivation at the lowest level of all stages.
* **Sawtooth waves**: A train of sharply contoured, triangular EEG waves of 2–6 Hz, maximal over the central region and often occurring before a burst of REMs.
* **Arousal**: An abrupt shift in EEG frequency to alpha, theta, or frequencies >16 Hz (but not spindles), lasting ≥3 seconds, with at least 10 seconds of stable sleep preceding the change. **Scoring of arousal during stage R requires a concurrent increase in chin EMG tone lasting at least 1 second.**
### 2. Scoring rules for each sleep stage
* **Stage W (wakefulness)**: Score the epoch as stage W if more than 50 % of the epoch meets any of the following criteria:
* **Rule W.1**: The EEG shows alpha rhythm over the occipital region.
* **Rule W.2**: Eye blinks at a frequency of 0.5–2 Hz are present.
* **Rule W.3**: Irregular, conjugate rapid eye movements are present, accompanied by normal or increased chin EMG tone.
* **Stage N1 (NREM Stage 1):**
* For individuals who generate an alpha rhythm:
* **Rule N1.1**: If attenuation of the alpha rhythm (replacement by LAMF activity) occurs for more than 50 % of the epoch, score stage N1.
* For individuals who do not generate an alpha rhythm:
* **Rule N1.2**: Commence scoring stage N1 from the earliest appearance of any of the following phenomena:
* EEG activity shifts into the 4–7 Hz range, with background frequencies slowed by ≥1 Hz compared with stage W.
* Vertex sharp waves appear.
* Slow eye movements appear.
* **Stage N2 (NREM Stage 2):**
* **Start of stage N2:**
* **Rule N2.1**: Begin scoring stage N2 if any one or both of the following waveforms occur (and N3 criteria are not met). The waveform must appear in the first half of the current epoch or the last half of the previous epoch:
* One or more K complexes (not associated with arousals).
* One or more sleep spindles.
* **Continuation of stage N2:**
* **Rule N2.2**: If an epoch consists of LAMF activity without K complexes or sleep spindles but follows an epoch scored as stage N2 by rule N2.1 and no arousal occurs, continue scoring as stage N2.
* **Rule N2.3 (Continuation after N3)**: An epoch following stage N3 that no longer meets N3 criteria, and does not meet criteria for stage W or stage R, is scored as stage N2.
* **End of stage N2:**
* **Rule N2.4**: End scoring stage N2 when any of the following events occur:
* Transition to stage W, stage N3, or stage R.
* An arousal occurs. The epoch after the arousal should be scored as stage N1 until a K complex or sleep spindle reappears.
* A major body movement occurs followed by slow eye movements. The epoch after the body movement should be scored as stage N1.
* **Stage N3 (NREM Stage 3):**
* **Rule N3.1**: Score stage N3 if ≥20 % of an epoch consists of slow wave activity (0.5–2 Hz, >75 µV in frontal channels).
* **Stage R (REM Sleep):**
* **Start of stage R (definite stage R):**
* **Rule R.1**: Score the epoch as stage R if all of the following phenomena are present:
* Low-amplitude, mixed-frequency (LAMF) EEG activity.
* Low chin EMG tone.
* Rapid eye movements (REMs).
* **Continuation of stage R:**
* **Rule R.2**: If an epoch is contiguous with a definite stage R epoch (before or after) and all of the following standards are met, continue scoring as stage R even if the epoch has no REMs:
* The EEG shows LAMF activity with no K complexes or sleep spindles.
* The chin EMG tone remains low.
* No arousal occurs.
* **End of stage R:**
* **Rule R.3**: End scoring stage R when any of the following events occur:
* Transition to stage W or stage N3.
* Chin EMG tone markedly increases above the stage R level, and the epoch meets criteria for stage N1.
* An arousal occurs followed by slow eye movements. Subsequent epochs should be scored as stage N1.
* K complexes or sleep spindles appear without REMs. Score the epoch as stage N2.
* **Scoring rules for major body movements:**
* **Definition**: A major body movement is when movement and muscle artifact obscure more than half of the epoch's EEG signal, making the sleep stage indeterminable.
* **Rule MBM.1**: If alpha rhythm can be identified in any part of the epoch, or the epochs immediately before and after are both stage W, score the epoch with the body movement as stage W.
* **Rule MBM.2**: In other situations, score the epoch containing the major body movement as the same stage as the epoch that follows.
---
# 3. Input Data
Below, an image sequence containing **three consecutive 30-second PSG epochs** will be provided, namely:
* the preceding epoch N-1
* the target epoch N (the central image)
* the subsequent epoch N+1
Your analysis must focus on the **central image labeled as the target epoch N**, but you may consider the preceding and subsequent epochs to understand dynamic changes.
---
# 4. Tasks and Instructions
Please strictly follow the steps below:
1. **Analyze the context**: Using the preceding (epoch N-1) and subsequent (epoch N+1) epoch images, analyze the dynamics of the target epoch N. Note that this is to understand trends, but your final judgement must be based on observing the target epoch N itself.
2. **Identify key features**: In the target epoch N, **identify all key waveforms and features in great detail**. Your description must include: channel names, occurrence times, waveform types, frequencies, amplitude estimates.
3. **Cite rules**: Explicitly identify the specific AASM rule numbers from the rule set that support your classification.
4. **Generate the rationale**: Integrate your findings into a **professional, concise rationale written without first-person pronouns**. You must include quantitative or semi-quantitative descriptions of amplitude, frequency, duration, etc.
5. **Format the output**: Your final analysis result may only be provided in the following JSON format.
---
# 5. Output Format Requirements
```json
{
"reasoning_text": "<Provide an extremely detailed description of the key waveform features in the EEG, EOG and EMG channels of the target epoch N, including but not limited to: channel names, occurrence times, waveform types, frequencies, amplitude estimates, and relationships with adjacent channels (e.g., overlap). Then, based on these observations, apply the AASM Version 3 rules to logically infer why the epoch belongs to the specified stage. The text must be professional, objective and coherent, and based solely on information from the three images.>",
"applicable_rules": ["<AASM 3.0 rule numbers supporting your judgement, provided as a list, e.g., W.1, N2.1, R.2, etc.>"],
"sleep_stage": "<Sleep stage assigned to target epoch N based on analysis of the three images> W/N1/N2/N3/R"
}
```
Each user turn provides three consecutive epoch images prefixed with Preceding epoch N-1: , **Target epoch N**: , and Subsequent epoch N+1: .
Intended Use
This model is intended solely for research on automated sleep staging and model interpretability. It is not a medical device, and its outputs must not be used for clinical diagnosis or patient care.
Citation
@article{deng2026sleepvlm,
title = {{SleepVLM}: A Rule-Grounded Vision-Language Model for Auditable Sleep Staging},
author = {Deng, Guifeng and Wang, Pan and Niu, Mengfan and Wang, Jiquan and Rao, Shuying and Xie, Junyi and
Chen, Xi'ang and Zhao, Sha and Pan, Gang and Guo, Wanjun and Li, Jianjun and Li, Tao and Jiang, Haiteng},
journal = {arXiv preprint arXiv:2603.26738},
year = {2026}
}
License
Derived from Qwen3.5-0.8B and released under the Apache License 2.0.
- Downloads last month
- -