Skip to content

Support nvidia/LocateAnything-3B - #28958

Merged
mickqian merged 7 commits into
sgl-project:mainfrom
Jyothirmaikottu:locate-anything-3b
Jun 29, 2026
Merged

mickqian merged 7 commits into
sgl-project:mainfrom
Jyothirmaikottu:locate-anything-3b

Conversation

@Jyothirmaikottu

@Jyothirmaikottu Jyothirmaikottu commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Add native support for nvidia/LocateAnything-3B, requested in #27674. LocateAnything is a visual grounding / detection model that emits structured outputs such as <ref>label</ref><box><x1><y1><x2><y2></box> (coordinates normalized to [0, 1000]), covering object detection, phrase grounding, scene-text detection, GUI grounding, and pointing.

The architecture is a MoonViT vision encoder + an InternVL-style mlp1 projector + a Qwen2 language-model backbone, so it reuses SGLang's existing MoonViT (kimi_vl_moonvit) and Qwen2 building blocks.

Modifications

  • configs/locate_anything.py — LocateAnythingConfig, a composite of MoonViTConfig (vision) + Qwen2Config (text) plus the grounding special-token ids. Registered in configs/__init__.py, utils/hf_transformers/common.py (_CONFIG_REGISTRY, keyed on model_type="locateanything"), and the multimodal_model_archs list in configs/model_config.py.
  • models/locate_anything.py — LocateAnythingForConditionalGeneration reusing MoonVitPretrainedModel and Qwen2ForCausalLM, with LocateAnythingMultiModalProjector (the mlp1 projector: LayerNorm over the merged width hidden_size * merge_h * merge_w, then Linear → GELU → Linear). Includes weight remapping for the HF checkpoint prefixes and tied-embedding handling. Also adds an optional LocateAnythingBoxGrammarLogitProcessor that constrains decoding inside a <box>...</box> block to a valid none / 2-coord point / 4-coord bbox pattern (opt-in via custom_logit_processor).
  • multimodal/processors/locate_anything.py — LocateAnythingImageProcessor that splits the prompt on the chat template's <image-N> placeholders (which the HF processor expands into <img> + <IMG_CONTEXT>×N + </img>).
  • Docs — new row under supported multimodal language models.
  • Tests — CPU unit tests for the config (composition + registry), projector shapes (incl. non-contiguous input), and the box-grammar logit-processor state machine.

Usage:

python3 -m sglang.launch_server --model-path nvidia/LocateAnything-3B --trust-remote-code

Clients should set skip_special_tokens=false so the <ref> / <box> grounding tokens survive in the output. The model's bundled chat template is used (do not override it).

Accuracy Tests

Validated end-to-end on an NVIDIA L4 GPU (server loads, /health OK). Across the model's task suite, outputs are correct and non-degenerate, e.g.:

Task Prompt Output
Detection Locate all the instances that matches the following description: remote control. two boxes — <64><152><273><244> and <522><160><578><390> (two remotes)
Phrase grounding Locate a single instance that matches the following description: the cat on the right. <box><541><52><998><775></box> (right side)
Pointing Point to: the remote control. two 2-coord points
Multi-category …person</c>tv</c>chair. person + tv + 4× chair, each with its own <ref>/<box>
No match …description: elephant. (absent) <ref>elephant</ref><box>None</box>

Unit tests: 17 passed (test/registered/unit/configs/test_locate_anything_config.py, test/registered/unit/models/test_locate_anything.py).

Note: only the standard autoregressive decoding path is implemented. The model's HF-native generation_mode="fast"/"hybrid" Parallel Box Decoding is not ported — it is a throughput optimization, not a correctness requirement.

Speed Tests and Profiling

N/A — new model support; no changes to existing kernels or shared forward paths.

Checklist

  • Format code with pre-commit (isort/black-compatible import ordering verified).
  • Add unit tests.
  • Update documentation.
  • Accuracy/speed benchmarks (functional grounding accuracy verified on L4; formal benchmark suite not run).
  • Follow the SGLang code style guidance.

Closes #27674


CI States

Latest PR Test (Base): ✅ Run #28312458017
Latest PR Test (Extra): 🚫 Run #28312985104

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@github-actions github-actions Bot added documentation Improvements or additions to documentation Multi-modal multi-modal language model labels Jun 22, 2026
@Jyothirmaikottu

Copy link
Copy Markdown
Contributor Author

/tag-run-ci-label

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native loading + forward verified end-to-end on a GB300 devbox (1×sm103): sglang resolves LocateAnythingForConditionalGeneration by architecture string with no transformers fallback, vision features route correctly (same prompt across 4 images → 4 distinct box coords, confirming MoonViT→mlp1→Qwen2 + <IMG_CONTEXT> embedding routing), all 4 grounding tasks finish=stop with no no-EOS runaway, 17 unit tests pass, and outputs align with the HF generation_mode='slow' reference (2/4 token-identical, 2/4 greedy argmax flips from trtllm_mha vs sdpa near-tie logits — backend numerical difference, not a correctness bug). Lint fixed (legacy docs/ row → docs_new/ + a hidden isort merge). Remaining findings below.

@JustinTong0323 JustinTong0323 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed at b396bc8b8c (after the review-feedback commit + black fix). The splitter image_grid_hws fallback is verified correct at runtime (real HF processor probe: pixel_values rows == sum(prod(hws)), so the feature_len guard passes and per-image split fires), and the projector/weight-loading matches the HF reference. Two new issues found by re-review (independently confirmed by codex) — both worth addressing before merge.

Comment thread python/sglang/srt/managers/mm_utils.py Resolved
Jyothirmaikottu and others added 5 commits June 27, 2026 23:12
Add native support for nvidia/LocateAnything-3B, a visual grounding/detection
model composed of a MoonViT vision encoder, an InternVL-style mlp1 projector,
and a Qwen2 language-model backbone. The model emits structured grounding
outputs such as <ref>label</ref><box>...</box> with coordinates normalized to
[0, 1000], covering object detection, phrase grounding, scene-text detection,
GUI grounding, and pointing.

- Composite LocateAnythingConfig (MoonViT vision + Qwen2 text + grounding tokens)
- LocateAnythingForConditionalGeneration reusing the existing MoonViT encoder
  and Qwen2 backbone, with an mlp1 projector (LayerNorm over the merged width)
- Image processor expanding the chat template's <image-N> placeholders
- Optional LocateAnythingBoxGrammarLogitProcessor that constrains decoding
  inside <box>...</box> to a valid none / point / bbox pattern
- Unit tests for the config, projector shapes, and box-grammar logic
- Docs entry under supported multimodal language models

Closes sgl-project#27674
CI rejects legacy docs/ edits (migrated to docs_new/). Add the multimodal
model row under docs_new/ and drop the legacy edit; merge the duplicated
base_processor import in the processor so isort passes.
- Split bundled multi-image items per-image by recognizing `image_grid_hws`
  (MoonViT models) in get_new_expanded_mm_items, restoring per-image
  RadixAttention cache granularity and the chunked-prefill fast path.
- Add LocateAnythingBoxGrammarLogitProcessor.build_sampling_params() so
  clients can wire custom_logit_processor + custom_params from the config
  token ids; document the opt-in/both-required contract in the docs row.
- Soften the box-grammar comment to state the no-unclosed-box-in-prompt
  assumption explicitly (only output_ids are scanned).
- Note unused ref_*/mlp_connector_layers config fields are kept for HF
  round-trip fidelity.
- Add tests for the >4-coord, coord_end-boundary, missing-token-id, and
  build_sampling_params branches.
Fold build_sampling_params signature onto one line; CI black-jupyter failed
on the prior review-feedback commit.
… add splitter + forward-shape tests

Address review feedback on the LocateAnything-3B port:

- build_sampling_params: the docstring example spread both returned keys into
  sampling_params, but custom_logit_processor is a top-level GenerateReqInput
  field, not a SamplingParams field (SamplingParams is a strict msgspec.Struct,
  so the unknown kwarg raised TypeError). Rewrite the example to put
  custom_params inside sampling_params and pass custom_logit_processor as a
  top-level request field, mirroring the OpenAI to_sampling_params path. Note
  the --enable-custom-logit-processor server flag prerequisite.

- get_new_expanded_mm_items: add a rank-2 guard before the per-image prod split.
  A flat 1-D grid (e.g. tensor([h, w]) with num_items==2) passed the length
  check but prod(dim=-1) collapsed it to a scalar and mis-split; now it falls
  back to the simple split instead.

- Add test/registered/unit/managers/test_mm_utils_split.py: CPU-registered
  regression tests for the splitter covering image_grid_hws / image_grid_thw /
  numpy / tensor splits, missing-grid fallback, flat-1D rejection, and
  non-bundled passthrough.

- Add forward-shape smoke tests for get_image_feature (CPU, MoonViT stubbed):
  pixel concat + projector wiring, multi-image ordering, numpy image_grid_hws
  coercion, and precomputed-embedding passthrough. The stub asserts on its
  inputs so a regression in the feature/grid wiring fails rather than passing
  on a fabricated shape.

- Docs: state the --enable-custom-logit-processor prerequisite and the
  two-field split in the LocateAnything row.
JustinTong0323

This comment was marked as outdated.

The 4 new TestGetImageFeatureWiring tests crashed at setup because
_bare_model used __new__ (bypassing __init__), so _modules was never
populated and the multi_modal_projector assignment raised
AttributeError. Add nn.Module.__init__(model) after __new__.
@JustinTong0323 JustinTong0323 added the run-ci CI: run the baseline test suite on this PR label Jun 28, 2026
@JustinTong0323

Copy link
Copy Markdown
Collaborator

/rerun-failed-ci

@JustinTong0323 JustinTong0323 left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mickqian
mickqian merged commit 473a278 into sgl-project:main Jun 29, 2026
299 of 336 checks passed
vstone-w pushed a commit to ClownBin/sglang that referenced this pull request Jul 2, 2026
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation Multi-modal multi-modal language model run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support for nvidia/LocateAnything-3B

3 participants