Metadata-Version: 2.4
Name: vlmbox
Version: 0.2.0
Summary: A lightweight research toolbox for vision-language models.
License-Expression: MIT
Project-URL: Homepage, https://github.com/czxvan/VLMBox
Project-URL: Repository, https://github.com/czxvan/VLMBox
Project-URL: Issues, https://github.com/czxvan/VLMBox/issues
Keywords: vision-language-models,multimodal,transformers,pytorch,research
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch<2.15,>=2.14.1
Requires-Dist: torchvision<0.30,>=0.29.1
Requires-Dist: transformers<6,>=5.22.1
Requires-Dist: modelscope>=1.40.2
Requires-Dist: numpy>=1.24
Requires-Dist: accelerate>=1.10
Requires-Dist: pillow>=10.0
Requires-Dist: PyYAML>=6.0
Provides-Extra: dev
Requires-Dist: pytest>=8.3; extra == "dev"
Requires-Dist: ruff>=0.14; extra == "dev"
Dynamic: license-file

# VLMBox

A small library for VLM research: prepare model inputs, inspect and edit decoder activations, trace generation, and optimize visual interventions.

| Object | Purpose |
|---|---|
| `VLM` | Model loading, preprocessing, execution, and decoder operations |
| `Renderer` | Image composition and trainable visual parameters |
| `Trainer` | Frozen-model optimization with your loss function |

## Install

In your own uv project (Python 3.11+):

```bash
uv add vlmbox
```

For local development from this checkout:

```bash
uv venv --python 3.11
uv pip install -e .
```

Local installation is editable. Native image-processing dependencies are included; checkpoints are downloaded from ModelScope.

## Quick start

```python
from PIL import Image
from vlmbox import VLM

vlm = VLM.from_pretrained("HuggingFaceTB/SmolVLM-500M-Instruct")
image = Image.new("RGB", (224, 224), "red")
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": image},
            {"type": "text", "text": "Describe the image briefly."},
        ],
    }
]
inputs = vlm.prepare(messages)
sequences = vlm.generate(inputs, max_new_tokens=16, do_sample=False)
new_tokens = sequences[:, inputs["input_ids"].shape[1] :]
print(vlm.processor.batch_decode(new_tokens, skip_special_tokens=True)[0])
```

Use `Image.open("image.jpg").convert("RGB")` for your own image. Set `local_files_only=True` when loading to require a cached checkpoint.

## Usage and reference

- [Usage](https://github.com/czxvan/VLMBox/blob/main/docs/usage.md): batching, activations, traces, rendering, loss functions, training, and runnable experiments.
- [API](https://github.com/czxvan/VLMBox/blob/main/docs/api.md): imports, signatures, and behavior contracts.
- [Architecture](https://github.com/czxvan/VLMBox/blob/main/docs/architecture.md): the three core objects and package boundaries.
- [Rendering protocol](https://github.com/czxvan/VLMBox/blob/main/docs/protocols/visual-input-rendering.md) and [YAML configuration](https://github.com/czxvan/VLMBox/blob/main/examples/image_render.yaml).

Layer indices are **zero-based decoder blocks**. Captures and traces return direct block outputs before final model normalization.

## Development

```bash
uv sync --frozen --extra dev
uv run pytest
uv run ruff check .
uv run ruff format --check .
```

CUDA integration tests require locally cached Qwen2.5-VL, InternVL, and SmolVLM checkpoints:

```bash
VLMBOX_RUN_GPU_INTEGRATION=1 uv run pytest tests/integration
```

[Release procedure](https://github.com/czxvan/VLMBox/blob/main/RELEASING.md) · [MIT license](https://github.com/czxvan/VLMBox/blob/main/LICENSE)
