Skip to content

fix(args): broadcast environment options across models - #682

Open
linjiaye929 wants to merge 2 commits into
michaelfeil:mainfrom
linjiaye929:codex/fix-env-engine-args-broadcast
Open

linjiaye929 wants to merge 2 commits into
michaelfeil:mainfrom
linjiaye929:codex/fix-env-engine-args-broadcast

Conversation

@linjiaye929

@linjiaye929 linjiaye929 commented Oct 13, 2026 •

Copy link
Copy Markdown

Summary

EngineArgs.from_env() uses zip_longest to align model IDs and option lists. With two semicolon-separated model IDs and ordinary singleton/default options, the second configuration receives None values and raises KeyError(None) while resolving its engine.

The v2 CLI already broadcasts singleton options and rejects other lengths that do not match the number of models. This change applies those same length rules to the Python environment factory:

  • Move the existing, unchanged AutoPadding and typer_option_resolve helpers to a dependency-free shared module.
  • Keep both names available from infinity_emb.cli.
  • Use the shared helper in EngineArgs.from_env() for its existing supported fields.
  • Document singleton broadcasting and per-model option lengths.

No inference, engine-iterable consumption, cache, embedding dimensions, or additional environment-parameter support is changed.

Reproduction

Set these before importing Infinity:

INFINITY_MODEL_ID="local/model-a;local/model-b"
INFINITY_ENGINE="debugengine"
INFINITY_DEVICE="cpu"

Then call EngineArgs.from_env(). On unmodified main it raises KeyError(None); with this change it produces two configurations. Equivalent values already work through the CLI's existing AutoPadding helper.

Validation

Linux, Python 3.12.14, NumPy 1.26.4, CPU-only PyTorch 2.8.0, sentence-transformers 3.3.1, pytest 8.4.2, Typer 0.12.5.

From libs/infinity_emb, with DO_NOT_TRACK=1 HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1:

python -m pytest tests/unit_test/test_args_from_env.py -q
  • 19 passed.
  • Same regression file on unchanged 040269bc: 12 failed, 6 passed, with the new-module import-identity check excluded as inapplicable to baseline.
  • Covers one, two and three models; defaults; singleton and per-model boolean, numeric and string options; fully explicit parallel-array controls; trailing separators; incompatible option lengths; and preserved CLI imports.
  • Lifecycle cases create real Infinity debugengine instances and exercise native batching, embedding and shutdown without model downloads or inference mocks. This is not pretrained-model inference or a quality benchmark.

Adjacent checks:

python -m pytest tests/unit_test/test_args_from_env.py tests/unit_test/test_args.py \
  tests/unit_test/test_engine.py::test_async_api_debug \
  tests/unit_test/test_engine.py::test_args_between_array_and_engine_same \
  tests/unit_test/test_sync_engine.py::test_sync_engine \
  tests/unit_test/test_sync_engine.py::test_sync_engine_double -q
python -m pytest tests/unit_test/test_cli.py -k 'help or wrong_batch_size or weird' -q
  • 30 passed in the combined run.
  • 6 passed, 2 deselected for existing CLI help/error checks.
  • ruff check ., changed-file formatting/codespell, and git diff --check pass.
  • mypy infinity_emb reports the same 16 missing-optional-dependency errors in 10 files on this branch and unchanged main; no new diagnostics.
  • Full CLI debug preload reached configuration construction but was blocked by missing FastAPI. Full CLI preload, HTTP-server tests, optional Pydantic validation, pretrained-model/accelerator suites, and full make precommit were not validated in this minimal environment.

Hosted CI status

For head 38d545132346e85c187937f5553e768d3c9c7421, the upstream workflow is completed with action_required. It has zero jobs, zero check runs and zero commit statuses. The reason is unconfirmed; no hosted tests have executed, so this is neither a hosted test pass nor a demonstrated code-test failure. The validation above is local CPU/debug-engine coverage only.

Checklist

  • Read the contribution guidelines.
  • Added regression tests.
  • Updated the Python engine documentation.
  • Contribution is compatible with the repository's MIT license.

AI assistance was used to prepare this contribution.

@linjiaye929
linjiaye929 marked this pull request as ready for review October 13, 2026 07:03
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T07:09:08.987892Z 38d5451 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

EngineArgs.from_env() now uses the same option-length rules as the v2 CLI.

  • Python environment settings now build complete configurations for every model.

linjiaye929 explicitly identifies mismatched-length rejection as intentional and additional environment-field support as unchanged. No actionable issues were found.

Reviews (1) · Last reviewed commit: "fix(args): broadcast environment options..." · Reviewed by Greptile

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38d5451323

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/docs/python_engine.md Outdated
Comment on lines +143 to +145
`INFINITY_MODEL_ID`. Like the v2 CLI, singleton options (including defaults)
apply to every model. A list with multiple option values must have exactly one
value per model; other lengths raise `ValueError`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Qualify the length guarantee for omitted options

When two models are configured through this documented factory with INFINITY_DEVICE="cuda" and INFINITY_DEVICE_ID="0;1", this guarantee is false: EngineArgs.from_env() never passes MANAGER.device_id to AutoPadding, while the EngineArgs.device_id default factory reads MANAGER.device_id[0] for every constructed object. The second value is therefore silently ignored (and a mismatched device-ID list is never rejected), which can place every engine on GPU 0; either pad this field too or explicitly limit the guarantee to the variables the factory handles.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Confirmed: the new documentation overstated the scope. On both unchanged main and this branch, a CPU/debugengine configuration with two models and INFINITY_DEVICE_ID=0;1 produces device IDs [[0], [0]]; 0;1;2 is also accepted. These checks exercised configuration construction only, without GPU inference.

aab9569 qualifies the documentation and from_env() docstring to the fields actually passed through the factory, explicitly notes the first-entry device-ID behavior and omitted vector-cache option, and points to explicit EngineArgs construction for those fields. Executable behavior is unchanged. All 19 focused tests still pass; formatting, lint, spelling and diff checks pass.

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.

1 participant