Skip to content

Inference Scaling

Generate K candidates, pick the best by CLIP score (or NVILA when ready).

from strands_sana import sana_inference_scale

result = sana_inference_scale(
    prompt="a cherry blossom branch in soft moonlight",
    model="sana-1.6b-1024",
    n_samples=4,
    score_fn="clip",    # or "first" to skip scoring
    seed_start=200,
)

print(result["best"])   # best candidate path + score
print(result["scores"]) # all 4 scores

How it works

graph LR
    P[Prompt] --> G[Generate K with seeds]
    G --> S[Score each with CLIP]
    S --> B[Return best + all]

    style B fill:#5e35b1,stroke:#333,color:#fff

Demo — 4 candidates

Cand 0

seed 200
CLIP 0.431

Cand 1

seed 201
CLIP 0.453

Winner

seed 202
CLIP 0.462 ← winner

Cand 3

seed 203
CLIP 0.459

When to use

  • ✅ Production where quality matters more than latency
  • ✅ Difficult prompts (compositional, off-distribution)
  • ✅ Building a "best-of-N" agent loop
  • ❌ Real-time UX (latency is K× single inference)

Score functions

score_fn Method Speed
"clip" OpenAI CLIP-vit-base-patch32 ~0.5s/image
"first" No scoring, return seed_start 0s

For more sophisticated scoring (NVILA-2B, ImageReward, MPS), add a custom score_fn — see API reference.