Skip to content

Make image laziness a declared contract with ImageReference - #572

Open
alok-108 wants to merge 2 commits into
allenai:mainfrom
alok-108:feat/image-reference-contract
Open

alok-108 wants to merge 2 commits into
allenai:mainfrom
alok-108:feat/image-reference-contract

Conversation

@alok-108

Copy link
Copy Markdown

Fixes #395.

Description

Replaces untyped functools.partial / closure lazy image loaders with an explicit ImageReference contract (resolve() and to_json()) so deferred image loading stays picklable, inspectable, and JSON-serializable across request construction, worker queues, resume hashing, CLI inspection, and JSONL output writers.

What changed

  • Core contract (src/olmo_eval/common/images.py, src/olmo_eval/common/types/base.py):
    • Defined ImageReference(ABC) with resolve() and to_json(), typed LMRequest.images with ImageReference, and added frozen, slotted, picklable implementations: PathImage, HfDatasetImage, HfDatasetImageList, ImageList, and CappedImageList (which slices HfDatasetImageList before decoding instead of materializing excess images).
    • Updated resolve_image and resolve_images to resolve ImageReference entries cleanly while preserving compatibility for raw paths, PIL images, and legacy callables.
    • Added encode_image_entry for structured JSON encoding.
  • Vision benchmarks & data loaders (src/olmo_eval/evals/vision/):
    • Updated lazy_hf_image, lazy_hf_image_list, and capped_image_list (evals/vision/data/images.py), VisionTask._attach_images (evals/vision/tasks/base.py), MmmuProTask._attach_images (evals/vision/benchmarks/mmmu_pro.py), TsvImageReference (evals/vision/benchmarks/cc_ocr.py), and PdfPageImage (evals/vision/benchmarks/olmocr_bench.py) to construct typed ImageReference objects instead of functools.partial callables.
  • Serialization, hashing, and CLI inspection:
    • src/olmo_eval/runners/io/writers.py & src/olmo_eval/inference/providers/replay.py: replaced _lazy_loader_placeholder with _request_json_default and _prediction_json_default, serializing ImageReference via to_json() instead of emitting "<partial>" while retaining legacy callable placeholders in write_requests_jsonl and strict rejection of non-JSON types in write_predictions_jsonl.
    • src/olmo_eval/runners/asynq/progress.py: handled ImageReference via to_json() in _hash_default prior to is_dataclass (avoiding dataclasses.asdict() traversal into HF Dataset objects) and skipped ImageReference values in _metadata_changes.
    • src/olmo_eval/cli/task/__init__.py & src/olmo_eval/common/inspection.py: serialized ImageReference and LMRequest.images cleanly in task inspect --json and inspect_request / format_value / _format_simple_value.
  • Tests (tests/core/test_images.py, tests/evals/vision/test_task_contracts.py, tests/runners/io/test_writers.py):
    • Added unit tests covering PathImage, HfDatasetImage, HfDatasetImageList, CappedImageList early truncation, ImageList / MmmuProTask._attach_images, TsvImageReference, PdfPageImage, pickle roundtrips, JSONL serialization, request_hash, _metadata_changes, and inspection formatting.

Affected results

None. Task specifications, prompts, scorers, and tests/evals/tasks/test_task_hashes.py hashes are unchanged; ImageReference resolves to the same PIL images as the previous lazy loaders while adding structured JSON metadata.

Type of Change

  • Refactoring (no functional changes)

Validation

Executed on Windows (win32, Python 3.13.1, commit 26c39af3a81b39812ed6ba5d4bfc8609e9494956) using uv run --frozen --no-sync --no-group vllm --extra clients --extra litellm --extra agents:

  • uv run --frozen --no-sync --no-group vllm --extra clients --extra litellm --extra agents ruff check src/ tests/ and ruff format --check src/ tests/ — passed (All checks passed!, 757 files already formatted)
  • uv run --frozen --no-sync --no-group vllm --extra clients --extra litellm --extra agents ty check --python-platform linux src/ — passed (All checks passed!)
  • ./scripts/check_file_sizes.sh — passed (All 1164 tracked files are within 1.00 MB.)
  • uv build — built source distribution and wheel cleanly
  • pytest tests/core/test_images.py -o addopts="" -v -W error::ResourceWarning — 6 passed
  • Focused multimodal/serialization/provider/hash sweep (tests/core/test_images.py, tests/evals/vision/, tests/runners/io/, tests/providers/test_replay_provider.py, tests/providers/test_huggingface_provider.py, tests/providers/test_sglang_provider.py, tests/core/harness/test_harness.py, tests/evals/tasks/test_task_hashes.py) — 463 passed, 4 skipped
  • Cross-platform test sweep (tests/common, tests/core, tests/evals, tests/harness, tests/inference, tests/providers, tests/runners, tests/cli/test_{arg_round_trip,dotlist_overrides,harness_overrides,output_dir_default,utils}.py, tests/cli/beaker/test_{example_configs,sglang_install}.py, tests/test_package.py, tests/test_readme.py, tests/test_runner.py, excluding the Windows-incompatible POSIX/pexpect.spawn/os.O_DIRECTORY/Unix-PATH files listed under Remaining work) — 4336 passed, 23 skipped; pytest tests/cli/test_results_upload.py -k "not sigterm" — 9 passed, 5 deselected
  • New tests added for new behavior (tests/core/test_images.py, tests/runners/io/test_writers.py)

Remaining work

  • Full Linux CI (uv run pytest tests/ --ignore=tests/integration -v) and Docker integration tests (tests/integration/) need to run on GitHub Actions Linux runners; on Windows, POSIX/Linux-specific test modules (test_http_command.py, test_http_session.py, test_owned_docker_deployment.py, test_sandbox_executor.py, test_terminal_bench_external.py, test_livecodebench.py, test_ruler_plus.py, test_vllm_server_startup.py, test_resume.py, test_results_upload.py[sigterm], tests/data/, tests/upload/, tests/scripts/, tests/cli/beaker/test_{build_image_script,launch,resume_access,upload_wiring}.py) were excluded or skipped.

@alok-108
alok-108 requested a review from a team as a code owner November 17, 2026 12:40

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ImageReference: make image laziness a declared contract

1 participant