-
Notifications
You must be signed in to change notification settings - Fork 10
fix: let HTTPClientConfig and template regen work on non-Linux #291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tests for scripts/regenerate_templates.py. | ||
|
|
||
| `_dump_defaults` must extract defaults without constructing nested | ||
| BaseModels that appear as default_factory, because construction runs | ||
| validators (which may have platform-dependent side effects). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from pydantic import BaseModel, Field, model_validator | ||
|
|
||
| _REPO_ROOT = Path(__file__).resolve().parents[3] | ||
| _SCRIPT = _REPO_ROOT / "scripts" / "regenerate_templates.py" | ||
|
|
||
|
|
||
| def _load_regenerate_templates(): | ||
| """Load scripts/regenerate_templates.py as a module (it is not a package).""" | ||
| if "regenerate_templates" in sys.modules: | ||
| return sys.modules["regenerate_templates"] | ||
| spec = importlib.util.spec_from_file_location("regenerate_templates", _SCRIPT) | ||
| assert spec and spec.loader | ||
| module = importlib.util.module_from_spec(spec) | ||
| sys.modules["regenerate_templates"] = module | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| class TestDumpDefaultsSkipsBaseModelFactory: | ||
| def test_basemodel_factory_does_not_run_validator(self): | ||
| """default_factory=<BaseModel subclass> must not invoke the model's validators.""" | ||
| rt = _load_regenerate_templates() | ||
|
|
||
| call_count = 0 | ||
|
|
||
| class Inner(BaseModel): | ||
| x: int = 42 | ||
|
|
||
| @model_validator(mode="after") | ||
| def _count(self): | ||
| nonlocal call_count | ||
| call_count += 1 | ||
| return self | ||
|
|
||
| class Outer(BaseModel): | ||
| inner: Inner = Field(default_factory=Inner) | ||
|
|
||
| # Sanity: constructing Inner() directly does invoke the validator. | ||
| Inner() | ||
| assert call_count == 1 | ||
|
|
||
| call_count = 0 | ||
| result = rt._dump_defaults(Outer) | ||
|
|
||
| assert call_count == 0, ( | ||
| "Inner validator was invoked — _dump_defaults called the factory " | ||
| "instead of recursing." | ||
| ) | ||
| assert result == {"inner": {"x": 42}} | ||
|
|
||
| def test_callable_factory_is_still_invoked(self): | ||
| """Factories that are callables (not BaseModel subclasses) must still be called.""" | ||
| rt = _load_regenerate_templates() | ||
|
|
||
| class Config(BaseModel): | ||
| tags: list[str] = Field(default_factory=lambda: ["default-tag"]) | ||
|
|
||
| result = rt._dump_defaults(Config) | ||
| assert result == {"tags": ["default-tag"]} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Tests for HTTPClientConfig construction on non-Linux platforms. | ||
|
|
||
| NUMA probing is Linux-only; auto-detecting num_workers must fall back | ||
| gracefully so HTTPClientConfig() can be constructed anywhere. | ||
| """ | ||
|
|
||
| from unittest.mock import patch | ||
|
|
||
| from inference_endpoint.endpoint_client import config as cfg | ||
| from inference_endpoint.endpoint_client.cpu_affinity import UnsupportedPlatformError | ||
|
|
||
|
|
||
| class TestAutoNumWorkersNonLinux: | ||
| def _clear_cache(self): | ||
| cfg._get_auto_num_workers.cache_clear() | ||
|
|
||
| def test_get_current_numa_node_unsupported_falls_back_to_min(self): | ||
| self._clear_cache() | ||
| with patch.object( | ||
| cfg, "get_current_numa_node", side_effect=UnsupportedPlatformError("darwin") | ||
| ): | ||
| assert cfg._get_auto_num_workers() == 10 | ||
|
|
||
| def test_get_cpus_in_numa_node_unsupported_falls_back_to_min(self): | ||
| self._clear_cache() | ||
| with ( | ||
| patch.object(cfg, "get_current_numa_node", return_value=0), | ||
| patch.object( | ||
| cfg, | ||
| "get_cpus_in_numa_node", | ||
| side_effect=UnsupportedPlatformError("darwin"), | ||
| ), | ||
| ): | ||
| assert cfg._get_auto_num_workers() == 10 | ||
|
|
||
| def test_http_client_config_constructs_when_numa_unsupported(self): | ||
| self._clear_cache() | ||
| with patch.object( | ||
| cfg, "get_current_numa_node", side_effect=UnsupportedPlatformError("darwin") | ||
| ): | ||
| c = cfg.HTTPClientConfig() | ||
| assert c.num_workers == 10 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.