Skip to main content

Local inference with Transformers

Load Valen from native Hugging Face weights in Python and answer SystemOne or Decisions questions on a CUDA GPU.

This route uses PyTorch and the native weights; no Valen SDK installation is needed. The model answers predicate, choice and score questions over text, images and video, and Valen-Decision-1.5 also answers bbox questions with a box in an image.

CPU, ONNX Runtime or the browser

For CPU, ONNX Runtime or browser inference, use ONNX & SDKs; the SDKs run the Valen-Decision-1.5 ONNX bundles, including bbox questions.

Install dependencies​

Use Python 3.10+ and a CUDA GPU supporting BF16. These commands create an isolated environment with Python 3.11:

Terminal
uv venv --python 3.11
source .venv/bin/activate
uv pip install torch torchvision transformers pillow av

Load a model​

Python
import torch
from transformers import AutoModel

model = (
AutoModel.from_pretrained(
"Valen-Team/Valen-Decision-1.5-0.8B",
trust_remote_code=True,
dtype="auto",
attn_implementation="sdpa",
)
.to("cuda")
.eval()
)
torch.set_float32_matmul_precision("highest")
torch.backends.cudnn.allow_tf32 = False

Replace 0.8B in the model ID with 2B, 4B, 9B or 27B to select another size. dtype="auto" preserves each model’s storage precision; the decision and grounding heads use FP32.

The first load downloads and caches native model weights. Once cached, add local_files_only=True to AutoModel.from_pretrained(...) to prevent downloads, or replace the model ID with a local model directory. Use native Valen-Decision-1.5-*B repositories here; load the Valen-Decision-1.5-*B-ONNX bundles through the SDKs.

Minimal inference check​

After loading the model, verify the path with one predicate question:

Python
result = model.predict({
"input": "A cat is on the sofa.",
"questions": [{"name": "cat", "type": "predicate", "instructions": "A cat is present."}],
}, execution="shared_state", temperature=1.0)
print(result["answers"][0]["probability"])

Inputs and parameters​

  • shared_state: questions and candidates share one sequence.
  • question: execute separate questions or branches.
  • temperature defaults to 1.0; a finite positive value scales candidate logits. A request-body value takes precedence over the keyword argument.
  • Native Python inference reads local image/video paths; relative paths resolve against media_root, the working directory by default.
  • The single-GPU HTTP plugins do not inherit every media capability of the native Python model; consult the backend capability table.

Next steps​

See also: API · ONNX / SDK · vLLM