agentleFS
sgl-projectsgl-project/sglang/.agents/skills/processor-mm-parity/SKILL.md

processor-mm-parity

Skill39k starsChanged 5 days agoApache-2.0View on GitHub

Add or verify a model family's multimodal (image) preprocessing in rust/sglang-processor's `mm` component, on top of Dynamo's `dynamo-multimodal`, so it matches SGLang's Python path bit for bit at every stage and end to end. Use when adding a multimodal family to sglang-processor or the Rust server, bumping `dynamo-multimodal`, regenerating `mm_parity` fixtures, or debugging a Rust-vs-Python multimodal mismatch.

  • Installs packages

Trending

More talk lately.about the whole repository

Jan 2026: 6 mentionsFeb 2026: 3 mentionsMar 2026: 2 mentionsApr 2026: 0 mentionsMay 2026: 2 mentionsJun 2026: 3 mentionsJul 2026: 1 mentionAug 2026: 3 mentionsSep 2026: 3 mentionsOct 2026: 7 mentionsNov 2026: 5 mentionsDec 2026: 0 mentions
Jan 2026Jul 2026Dec 2026
Mentions a month of the sgl-project/sglang repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about sgl-project/sglang

The biggest 5 of 71 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 71

Talked about on GitHub, YouTube, Bluesky, Hacker News and Stack Overflow (71 times).

On GitHub · 44

39 more on GitHub

On YouTube · 21

16 more on YouTube

On Bluesky · 4

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never patch a fixture to match Rust: Every mismatch gets one of two fixes:

    line 26
  2. Very specific:

    Sizes: every resize boundary (below min_pixels, above max_pixels, sides smaller than the resize factor), and the aspect-ratio limit on both …

    line 112
  3. Very specific:

    Rejections: every input Python rejects is recorded as error and must be rejected by Rust.

    line 123
  4. Very specific:

    Every fixture covers the resize shapes, a two-image prompt and the pixel overrides.

    line 135
  5. Distinctive:

    Every family runs these before the host serves it, and again after any Dynamo bump:

    line 181

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Processor multimodal parity

The principle

Match Python bit for bit, at every stage and end to end. For the same request, the Rust path must produce exactly what SGLang's Python path produces:

  • the same resolved processor parameters;
  • the same decoded pixels;
  • the same feature bytes;
  • the same expanded ids and offsets;
  • the same positions;
  • the same model kwargs;
  • the same scheduler inputs.

The whole served request must also come out the same. It follows that:

  • No tolerances. No allclose, no "within 1 ULP", no "close enough on MMMU". Compare bytes and hashes of bytes.
  • Python is the reference. Dynamo is the implementation. SGLang code exists only where the two differ, and each such piece names the Python source it mirrors.
  • Never patch a fixture to match Rust. Every mismatch gets one of two fixes:
    • fix Dynamo upstream (ai-dynamo/frontend-crates, multimodal/), or fix SGLang's side (the spec gate in rust_server/multimodal.py, or src/mm/mod.rs) when the rule is SGLang's;
    • or record it as a known_gap, with the reason and the upstream fix. The test keeps reporting it and fails once it matches.
  • Stage parity is necessary, not sufficient. Each stage is checked on its own, so a mismatch is located immediately. The end-to-end check then proves the stages compose.

The one sanctioned difference is the content hash. Rust hashes the encoded bytes with blake3; Python hashes the feature with sha256. It is cache identity only and never reaches the model, so outputs cannot depend on it. Anything else that cannot match is a known gap, not an exception.

The reference: Python's CPU path

Python itself takes different paths on different hosts. The reference is the CPU path, which every fixture records:

  • PIL decode (utils/common.py::_load_image), then convert("RGB") in base_processor._load_single_item. There is no EXIF transpose unless the processor sets smart_rgb_conversion.
  • The HF image processor's CPU kernels: torchvision on a uint8 tensor (the default backend), or PIL with --image-processor-backend pil.

On a CUDA host, Python's default deviates from that reference in two ways:

  • It decodes JPEG with nvJPEG (gpu_image_decode, on by default in base_processor).
  • It runs the torchvision image processor on cuda:<base_gpu_id> (_fast_image_processor_device).

Both are Python disagreeing with itself. Measure them and report them; never copy them into Rust.

The PIL backend's bicubic output changes across Pillow releases, and SGLang does not pin Pillow. Every fixture records the Pillow version it was generated under. Regenerate under that version, or regenerate every fixture together under a new one.

Stages

#StagePython sourceRustChecked by
1Spec: processor params from the loaded HF processor plus server argsget_processor (utils/hf_transformers/processor.py), --image-processor-backend, --mm-process-configresolved in Python by rust_server/multimodal.py::RustMmProcessor.resolve_spec, handed over as MmSpec; Dynamo registry::build_processormm_parity cases record the resolved spec, per backend and per override
2Fetch: source to bytesget_image_byteshost (sglang-server/src/multi_modality/)host unit tests: data URL, bare base64, file://, http, limits
3Decode: bytes to RGB_load_image, _load_single_itemDynamo image::decode::decode_rgbthe corpus (below); a reject must reject
4Features: resize, normalize, patchifythe HF image processorDynamo process_itemfeature_sha256 and feature_shapes per item
5Expansion: placeholders to feature tokensbase_processor.build_input_ids, get_mm_items_offsetDynamo layout and apply_layoutinput_ids_sha256, num_input_ids, offsets
6PositionsMRotaryEmbedding.get_rope_index or the family's shortcutDynamo positionsmrope_sha256, mrope_delta
7Model kwargsmodel_specific_data (e.g. image_grid_thw)ProcessedItem.auximage_grid_thw
8Chat with media: prompt plus ordered media listprocess_content_for_template_format, _apply_jinja_templaterender/tests/parity.rs media cases (processor-model-parity)
9Scheduler handoff: MultimodalDataItem fieldsthe processor's MultimodalProcessorOutputserver multi_modality/ and rust_server/multimodal.py::wrap_encodedserver and Python unit tests: every field the scheduler reads
E2EThe served requestthe Python serverthe Rust server (SGLANG_RUST_SERVER=1)"End to end": bit-exact inputs and outputs, MMMU and MMMU-Pro, serving benchmarks

Where a family's code goes

  • Dynamo, upstream: the family's process_item, layout, positions, its ProcessorSpec arm, and its spec_from_hf_configs branch. Anything HF ships belongs there: class defaults, kernels, layout.
  • src/mm/mod.rs never branches on a family. It runs Dynamo's stages in order.
  • Python rust_server/multimodal.py: one RUST_MM_FAMILIES entry, which checks that the processor class is SGLang's own, and the family's spec in resolve_spec, read from the loaded HF processor. The server's MmSpec (sglang-server/src/message/config.rs) gets the matching MmFamily arm.

Method

  1. Pick the checkpoints from the family's cookbook page (docs/cookbook/). Include one per distinct processor config, e.g. a different patch size or size style. Pin each revision.
  2. Trace Python stage by stage for the family (the table above). Write down every transformation and every rejection; this is the divergence inventory.
  3. Extend the corpus in tests/scripts/generate_mm_parity.py (CORPUS) until it covers each inventory item, and add cases in cases(). Images must be small and deterministic.
  4. Generate fixtures (below) and run tests/mm_parity.rs.
  5. Fix each failure at the stage it belongs to: Dynamo for HF behavior, SGLang's gate or src/mm/mod.rs for SGLang's. Until an upstream fix ships, add the case to KNOWN_GAPS with the reason and the upstream PR.
  6. Run end to end (below): the bit-exact check, MMMU and MMMU-Pro on both servers, and the serving benchmarks, before the host serves the family.

Corpus checklist

Each item below needs at least one case:

  • Sizes: every resize boundary (below min_pixels, above max_pixels, sides smaller than the resize factor), and the aspect-ratio limit on both sides.
  • Modes: L, LA, P, P with transparency, RGBA, and 16-bit.
  • JPEG: baseline, progressive, 4:4:4 and subsampled, CMYK, and EXIF orientation.
  • Other formats: animated GIF (first frame), WebP lossy and lossless with alpha, BMP.
  • Prompts: multiple images in one prompt.
  • Server args: each backend, and each --mm-process-config key Python honors and each it rejects.
  • Rejections: every input Python rejects is recorded as error and must be rejected by Rust.

Generating fixtures

cd rust/sglang-processor
pip install --target /tmp/pillow pillow==<the fixtures' "pillow">
PYTHONPATH=/tmp/pillow:$REPO/python \
    python tests/scripts/generate_mm_parity.py <hf-model-id> [--revision <sha>]

Every fixture covers the resize shapes, a two-image prompt and the pixel overrides. Decoding does not depend on the model or the backend, so only one fixture per family runs the format sweep and the PIL backend (--formats); a new decoder or backend path is added there.

The generator downloads only the processor and tokenizer files. It loads them through SGLang's get_processor, records the spec SGLang's Rust MM gate resolves (RustMmProcessor.resolve_spec), and runs process_mm_data_async on the CPU path, with GPU decode and the GPU image device turned off. It writes tests/fixtures/mm_parity/<model>.json and any missing corpus images. Each case carries its spec, so cargo test runs offline.

Verify

cd rust
cargo test -p sglang-processor --locked --test mm_parity --test mm_single_thread
cargo clippy -p sglang-processor --all-targets --locked -- -D warnings

mm_single_thread guards the host's threading model. process runs inline on the caller's thread; the server's MM worker pool supplies the concurrency.

End to end

Stage parity proves each piece. End to end proves they compose into the same served model. Run the Python server and the Rust server (SGLANG_RUST_SERVER=1) on the same checkpoint with the model's cookbook flags, and run every check below against both. Report each pair of numbers with its harness, settings and hardware.

Because Python's CUDA defaults deviate from its CPU reference (see "The reference"), the bit-exact checks run on inputs where the two coincide: non-JPEG images with --image-processor-backend pil. Report the default-config delta (nvJPEG, CUDA resize) separately, as Python's own.

1. Identical inputs and outputs (bit-exact)

Send the same requests to both servers, through /generate and through chat.

  • Scheduler inputs: prompt ids, image_grid_thw, offsets and feature bytes must be identical. Dump them on both sides.
  • Outputs: greedy output tokens and their logprobs must be identical, under deterministic inference so that batching adds no noise.

2. Accuracy benchmarks

Every family runs these before the host serves it, and again after any Dynamo bump:

  • MMMU. simple_eval_mmmu_vlm.MMMUVLMEval (run_eval with eval_name="mmmu"), the same subset and sampler on both servers. sgl-eval does not ship plain MMMU, so this in-tree harness is the allowed exception (.claude/rules/prefer-sgl-eval.md). test/registered/vlm/test_rust_native_mm_mmmu.py is the CI form: it runs the Rust server over /generate with a gate calibrated against Python.
  • MMMU-Pro. sgl-eval run mmmu_pro and mmmu_pro_vision against each server's /v1/chat/completions. Use the version pinned in the test extra of python/pyproject.toml, from its own virtualenv, with the model's recommended sampling (--load-preset-from-model-id, or pass the settings explicitly).

With identical inputs (check 1), Python and Rust scores must agree at temperature 0. Any gap is a bug: find the first stage that differs. At the model's recommended sampling, they must agree within run-to-run noise. Measure that noise with repeated runs on one server; don't assume it. When adding a family, calibrate its CI gate from these runs and say how in the test.

3. Performance benchmarks

Parity must not cost throughput.

  • Serving: python -m sglang.bench_serving --dataset-name image (and --dataset-name mmmu) against both servers, and against the previous Rust server when replacing a pipeline. Compare request throughput, TTFT and end-to-end latency at the same concurrency.
  • Preprocessing: per-image p50/p99 on the MM worker, so a regression in decode or resize is visible apart from the model.

Pitfalls

  • A Dynamo bump can change any stage silently. Rerun every fixture after bumping dynamo-multimodal.
  • Pillow is unpinned. A fixture generated under another Pillow version fails PIL-backend cases for reasons unrelated to the code under test.
  • The Python processor reads gpu_image_decode from the class, not the instance. Setting it on the instance leaves nvJPEG on.
  • Python's --mm-process-config image overrides reach the HF processor at call time, and Python falls back to decode-and-retokenize when its own placeholder count disagrees. The fixture records what Python finally produced.
  • A test image set limited to PNG hides decoder differences; sglang-mm's JPEG mismatch went unnoticed that way. Keep JPEG in every family's cases.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.