Skip to content

refactor: share concurrency-limiting semaphore across model servers #1655

Open

Description

@cwing-nvidia

Context

While reviewing #1286, @cmunley1 noted that the per-process concurrency-limiting semaphore initialized in inference_provider/app.py is duplicated logic and could be reused/shared somewhere.

# responses_api_models/inference_provider/app.py
self._semaphore = Semaphore(self.config.num_concurrent_requests)

Problem

The same semaphore-init pattern is duplicated across multiple model servers:

  • responses_api_models/inference_provider/app.py — Semaphore(self.config.num_concurrent_requests)
  • responses_api_models/azure_openai_model/app.py — Semaphore(self.config.num_concurrent_requests) (identical)
  • responses_api_models/openai_model/app.py — asyncio.Semaphore(max_concurrent_requests) with a nullcontext() fallback when unlimited

(Note: vllm_model does not currently use a semaphore at all — no num_concurrent_requests / _semaphore.)

The base classes SimpleResponsesAPIModel / BaseResponsesAPIModelConfig in nemo_gym/base_responses_api_model.py don't define num_concurrent_requests or a semaphore, so there's no shared home for this today.

Proposed change

Lift the concurrency-limit config field + semaphore init into the base model config/class so all model servers can share a single implementation, e.g.:

  • Add an optional num_concurrent_requests (or max_concurrent_requests) field to BaseResponsesAPIModelConfig
  • Initialize a self._semaphore (falling back to nullcontext() when unlimited) in the base model_post_init
  • Migrate inference_provider, azure_openai_model, and openai_model to use it, reconciling the naming/default differences

Notes

  • Out of scope for feat: add inference_provider server for hosted inference providers #1286 (which only adds the inference_provider server); tracking as a follow-up to avoid touching unrelated model servers in that PR.
  • Should reconcile the differing field names (num_concurrent_requests vs max_concurrent_requests) and defaults (1000 vs None/unlimited) during the refactor.

Ref #1286

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions