Instructions to use datalab-to/chandra with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use datalab-to/chandra with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="datalab-to/chandra") 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)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("datalab-to/chandra") model = AutoModelForMultimodalLM.from_pretrained("datalab-to/chandra") 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use datalab-to/chandra with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "datalab-to/chandra" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "datalab-to/chandra", "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/datalab-to/chandra
- SGLang
How to use datalab-to/chandra 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 "datalab-to/chandra" \ --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": "datalab-to/chandra", "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 "datalab-to/chandra" \ --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": "datalab-to/chandra", "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 datalab-to/chandra with Docker Model Runner:
docker model run hf.co/datalab-to/chandra
`Qwen3VLModel` object has no attribute 'generate'
Hi Datalab Team,
Thanks for releasing this model!.
I am trying to run sample inference in a H100 DGX using provided HF code and I am getting mention error.
File "/projects/data/teams/data_team/indic_ocr_eval/.venv/lib/python3.11/site-packages/chandra/model/hf.py", line 34, in generate_hf
generated_ids = model.generate(**inputs, max_new_tokens=max_output_tokens)
^^^^^^^^^^^^^^
File "/projects/data/teams/data_team/indic_ocr_eval/.venv/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1964, in __getattr__
raise AttributeError(
AttributeError: 'Qwen3VLModel' object has no attribute 'generate'
I double checked on project requirements, and they look okay
accelerate 1.11.0
transformers 4.57.1
torch 2.9.0
torchvision 0.24.0
qwen-vl-utils 0.0.14
You inputs will be appreciated!
from transformers import Qwen3VLForConditionalGeneration
model = Qwen3VLForConditionalGeneration.from_pretrained(
"datalab-to/chandra",
trust_remote_code=True,
torch_dtype=torch.float16,
device_map="auto"
).eval()
even I faced the same issue try using Qwen3VLForConditionalGeneration this instead of automodel that helped me
Hi @Rajneel18
If possible can you share sample inference script? This is what i used
model.processor = AutoProcessor.from_pretrained("datalab-to/chandra")
img_path = "/projects/data/teams/data_team/indic_ocr_eval/synth_data/hindi/images/level_1/Devanagari_Anek_Devanagari_5_n_pages_1_1.png"
PIL_IMAGE = load_image(img_path)
batch = [
BatchInputItem(
image=PIL_IMAGE,
prompt_type="ocr_layout"
)
]
result = generate_hf(batch, model)[0]
markdown = parse_markdown(result.raw)
I am getting cuda related error which could due to issue due tokeniser
torch.AcceleratorError: CUDA error: device-side assert triggered
Search for `cudaErrorAssert' in https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html for more information.
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions
Hi @carbene101
This worked for me too:
model = Qwen3VLForConditionalGeneration.from_pretrained(
"datalab-to/chandra",
trust_remote_code=True,
dtype="auto",
device_map="auto"
).eval()
full code:
from transformers import AutoModel, AutoProcessor, Qwen3VLForConditionalGeneration
from chandra.model.hf import generate_hf
from chandra.model.schema import BatchInputItem
from chandra.output import parse_markdown
from PIL import Image
PIL_IMAGE = Image.open("path to your image").convert("RGB")
model = Qwen3VLForConditionalGeneration.from_pretrained(
"datalab-to/chandra",
trust_remote_code=True,
dtype="auto",
device_map="auto"
).eval()
model.processor = AutoProcessor.from_pretrained("datalab-to/chandra")
batch = [
BatchInputItem(
image=PIL_IMAGE,
prompt_type="ocr_layout"
)
]
result = generate_hf(batch, model)[0]
markdown = parse_markdown(result.raw)
print(markdown)
Hi Team and @carbene101 , thanks for releasing the model, but I am facing the issue as ValueError: Image features and image tokens do not match: tokens: 630, features 630 when running this script
from transformers import AutoModel, AutoProcessor, Qwen3VLForConditionalGeneration
from chandra.model.hf import generate_hf
from chandra.model.schema import BatchInputItem
from chandra.output import parse_markdown
from PIL import Image
image_file = '../../201_300_1_21.jpg'
PIL_IMAGE = Image.open(image_file).convert("RGB")
model = Qwen3VLForConditionalGeneration.from_pretrained(
"datalab-to/chandra",
trust_remote_code=True,
dtype="auto",
device_map="auto"
).eval()
model.processor = AutoProcessor.from_pretrained("datalab-to/chandra")
batch = [
BatchInputItem(
image=PIL_IMAGE,
prompt_type="ocr_layout"
)
]
result = generate_hf(batch, model)[0]
markdown = parse_markdown(result.raw)
print(markdown)
Using the Qwen3VL model loader works for me. Try this out! π
#working
import torch
from transformers import AutoProcessor, Qwen3VLForConditionalGeneration
from chandra.model.hf import generate_hf
from chandra.model.schema import BatchInputItem
from chandra.output import parse_markdown
from PIL import Image
model_name = "datalab-to/chandra"
Load generation-capable model
model = Qwen3VLForConditionalGeneration.from_pretrained(
model_name,
torch_dtype=torch.bfloat16,
device_map="auto",
attn_implementation="sdpa"
)
processor = AutoProcessor.from_pretrained(model_name)
model.processor = processor
Prepare your input
PIL_IMAGE = Image.open("your_file_here.jpg").convert("RGB")
#PIL_IMAGE = PIL_IMAGE.resize((600,800))
batch = [
BatchInputItem(image=PIL_IMAGE, prompt_type="ocr_layout")
]
Generate
result = generate_hf(batch, model)[0]
markdown = parse_markdown(result.raw)
print(markdown)
Hi @sushruthb , thanks for the help but I am getting same error ValueError: Image features and image tokens do not match: tokens: 630, features 630.
Please share me the requirements file if possible for you.
Mine versions are
torch:2.9.0
transformers:4.57.1
chandra-ocr:0.1.8
pillow:12.0.0