-
Notifications
You must be signed in to change notification settings - Fork 305
Fix nvbug6084457: Make NVLINK_MAX_LINKS version-dependent #2192
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 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
637a218
Improve NVML_NVLINK_MAX_LINKS dynamic handling
mdboom 7e78548
Fix bug
mdboom 16721e5
Fix bug
mdboom 8a51cf0
Vendor the Deprecated library
mdboom 0120702
Fix error message
mdboom 93c3a77
Cleanup
mdboom 0e2af09
Document NVLink API lifecycle changes
rwgk 42f2189
Update AGENTS.md instructions
mdboom 17b5ac9
Apply suggestion from @mdboom
mdboom a74767a
Update AGENTS.md as suggested in the PR
mdboom 5499580
Merge remote-tracking branch 'upstream/main' into nvlink-max-links-dy…
mdboom 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,3 +145,97 @@ so that they are documented but don't appear in the main index. | |
| ### API stability | ||
|
|
||
| Reviews should point out where existing public APIs are broken. | ||
|
|
||
| ### Deprecation and API lifecycle | ||
|
|
||
| `cuda.core` follows SemVer (see `docs/source/support.rst`): | ||
|
|
||
| - **New APIs** may be added at any time (`x.Y.0`). | ||
| - **Breaking removals** only happen in **major releases** (`X.0.0`). | ||
| - Per the support policy, a deprecation notice must be present for **at least | ||
| one minor release** before the API is actually removed. | ||
| - Changes should be notated in the code and also in the release notes in the | ||
| "Deprecated APIs" section. | ||
|
|
||
| **Annotating a new API** — Use the `versionadded` decorator from the vendored | ||
| `cuda.core._vendored.deprecated.sphinx` module: | ||
|
|
||
| ```python | ||
|
|
||
| from cuda.core._vendored.deprecated.sphinx import versionadded | ||
|
|
||
| @versionadded(version="1.2.0") | ||
| def new_feature(...): | ||
| """Short description. | ||
| """ | ||
| ``` | ||
|
|
||
| Alternatively, if the vagaries of how we implement functions in Cython does not | ||
| allow this, you can add the reST `versionadded` directive directly: | ||
|
|
||
| ```python | ||
| def new_feature(...): | ||
| """Short description. | ||
|
|
||
| .. versionadded:: 1.2.0 | ||
| """ | ||
| ``` | ||
|
|
||
| **Annotating a changed API** — Use the `versionchanged` decorator from the | ||
| vendored `cuda.core._vendored.deprecated.sphinx` module: | ||
|
|
||
| ```python | ||
|
|
||
| from cuda.core._vendored.deprecated.sphinx import versionchanged | ||
|
|
||
| @versionchanged(version="1.2.0", reason="The old version was broken because...") | ||
| def new_feature(...): | ||
| """Short description. | ||
| """ | ||
| ``` | ||
|
|
||
| Alternatively, if the vagaries of how we implement functions in Cython does not | ||
| allow this, you can add the reST `versionchanged` directive directly: | ||
|
|
||
| ```python | ||
| def new_feature(...): | ||
| """Short description. | ||
|
|
||
| .. versionchanged:: 1.2.0 | ||
| The old version was broken because... | ||
| """ | ||
| ``` | ||
|
|
||
| **Deprecating an existing API** — use the `@deprecated` decorator from the | ||
| vendored `cuda.core._vendored.deprecated.sphinx` module and add a | ||
| `.. deprecated::` directive in the docstring. The decorator emits a | ||
| `DeprecationWarning` at call time; the docstring directive surfaces it in the | ||
| generated docs. | ||
|
|
||
| ```python | ||
| from cuda.core._vendored.deprecated.sphinx import deprecated | ||
|
|
||
| @deprecated(version="1.2.0", reason="Use `new_feature` instead.") | ||
| def old_feature(...): | ||
| """Short description. | ||
| """ | ||
| ``` | ||
|
|
||
| Rules to follow when deprecating: | ||
|
|
||
| - The `version=` argument must be the **first** in which the | ||
| deprecation appears, not the release in which removal is planned. | ||
| - The `reason=` string must name the replacement (if one exists) so users | ||
| know what to migrate to. | ||
| - Keep the old implementation fully functional — do not change its behavior, | ||
| only add the decorator. | ||
| - The deprecated API must remain in the codebase for **at least one full minor | ||
| release cycle** before it can be removed in a subsequent major release. | ||
|
|
||
| **Removing a deprecated API** — removals land in a **major release**. Before | ||
| removing, verify that the deprecation has been present since at least the | ||
| previous minor release. Remove the decorator, the implementation, and any | ||
| `__all__` entry; update `api.rst` and the release notes accordingly. | ||
|
|
||
| At some point in the future, we will provide automation for removal of | ||
| deprecated APIs. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems purely informational and speculative, not actionable for an agent. Do we need it here? |
||
Empty file.
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,6 @@ | ||
| # Vendored from the Deprecated package (https://pypi.org/project/Deprecated/), | ||
| # version 1.3.1, (c) Laurent LAPORTE, MIT License. | ||
| # Modified to remove the dependency on the `wrapt` package. | ||
|
|
||
| from cuda.core._vendored.deprecated.classic import deprecated | ||
| from cuda.core._vendored.deprecated.params import deprecated_params |
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,111 @@ | ||
| # Vendored from the Deprecated package (https://pypi.org/project/Deprecated/), | ||
| # version 1.3.1, (c) Laurent LAPORTE, MIT License. | ||
| # Modified to remove the dependency on the `wrapt` package. | ||
|
|
||
| import functools | ||
| import inspect | ||
| import warnings | ||
|
|
||
| # stacklevel=2 points past the wrapper to the actual call site | ||
| _routine_stacklevel = 2 | ||
| _class_stacklevel = 2 | ||
|
|
||
| string_types = (bytes, str) | ||
|
|
||
|
|
||
| class ClassicAdapter: | ||
| """ | ||
| Classic adapter -- *for advanced usage only* | ||
|
|
||
| This adapter is used to get the deprecation message according to the wrapped | ||
| object type: class, function, standard method, static method, or class method. | ||
|
|
||
| This is the base class of the :class:`~deprecated.sphinx.SphinxAdapter` class | ||
| which is used to update the wrapped object docstring. | ||
| """ | ||
|
|
||
| def __init__(self, reason="", version="", action=None, category=DeprecationWarning, extra_stacklevel=0): | ||
| self.reason = reason or "" | ||
| self.version = version or "" | ||
| self.action = action | ||
| self.category = category | ||
| self.extra_stacklevel = extra_stacklevel | ||
|
|
||
| def get_deprecated_msg(self, wrapped, instance): | ||
| if instance is None: | ||
| if inspect.isclass(wrapped): | ||
| fmt = "Call to deprecated class {name}." | ||
| else: | ||
| fmt = "Call to deprecated function (or staticmethod) {name}." | ||
| else: | ||
| if inspect.isclass(instance): | ||
| fmt = "Call to deprecated class method {name}." | ||
| else: | ||
| fmt = "Call to deprecated method {name}." | ||
| if self.reason: | ||
| fmt += " ({reason})" | ||
| if self.version: | ||
| fmt += " -- Deprecated since version {version}." | ||
| return fmt.format(name=wrapped.__name__, reason=self.reason or "", version=self.version or "") | ||
|
|
||
| def __call__(self, wrapped): | ||
| if inspect.isclass(wrapped): | ||
| old_new1 = wrapped.__new__ | ||
|
|
||
| def wrapped_cls(cls, *args, **kwargs): | ||
| msg = self.get_deprecated_msg(wrapped, None) | ||
| stacklevel = _class_stacklevel + self.extra_stacklevel | ||
| if self.action: | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter(self.action, self.category) | ||
| warnings.warn(msg, category=self.category, stacklevel=stacklevel) | ||
| else: | ||
| warnings.warn(msg, category=self.category, stacklevel=stacklevel) | ||
| if old_new1 is object.__new__: | ||
| return old_new1(cls) | ||
| return old_new1(cls, *args, **kwargs) | ||
|
|
||
| wrapped.__new__ = staticmethod(wrapped_cls) | ||
| return wrapped | ||
|
|
||
| elif inspect.isroutine(wrapped): | ||
| adapter = self | ||
|
|
||
| @functools.wraps(wrapped) | ||
| def wrapper(*args, **kwargs): | ||
| msg = adapter.get_deprecated_msg(wrapped, None) | ||
| stacklevel = _routine_stacklevel + adapter.extra_stacklevel | ||
| if adapter.action: | ||
| with warnings.catch_warnings(): | ||
| warnings.simplefilter(adapter.action, adapter.category) | ||
| warnings.warn(msg, category=adapter.category, stacklevel=stacklevel) | ||
| else: | ||
| warnings.warn(msg, category=adapter.category, stacklevel=stacklevel) | ||
| return wrapped(*args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
||
| else: | ||
| raise TypeError(repr(type(wrapped))) | ||
|
|
||
|
|
||
| def deprecated(*args, **kwargs): | ||
| """ | ||
| Decorator which can be used to mark functions as deprecated. | ||
|
|
||
| It will result in a warning being emitted when the function is used. | ||
| """ | ||
| if args and isinstance(args[0], string_types): | ||
| kwargs["reason"] = args[0] | ||
| args = args[1:] | ||
|
|
||
| if args and not callable(args[0]): | ||
| raise TypeError(repr(type(args[0]))) | ||
|
|
||
| if args: | ||
| adapter_cls = kwargs.pop("adapter_cls", ClassicAdapter) | ||
| adapter = adapter_cls(**kwargs) | ||
| wrapped = args[0] | ||
| return adapter(wrapped) | ||
|
|
||
| return functools.partial(deprecated, **kwargs) |
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,52 @@ | ||
| # Vendored from the Deprecated package (https://pypi.org/project/Deprecated/), | ||
| # version 1.3.1, (c) Laurent LAPORTE, MIT License. | ||
| # Modified to remove the dependency on the `wrapt` package. | ||
|
|
||
| import collections | ||
| import functools | ||
| import inspect | ||
| import warnings | ||
|
|
||
|
|
||
| class DeprecatedParams: | ||
| """ | ||
| Decorator for functions where one or more parameters are deprecated. | ||
| """ | ||
|
|
||
| def __init__(self, param, reason="", category=DeprecationWarning): | ||
| self.messages = {} | ||
| self.category = category | ||
| self.populate_messages(param, reason=reason) | ||
|
|
||
| def populate_messages(self, param, reason=""): | ||
| if isinstance(param, dict): | ||
| self.messages.update(param) | ||
| elif isinstance(param, str): | ||
| fmt = "'{param}' parameter is deprecated" | ||
| reason = reason or fmt.format(param=param) | ||
| self.messages[param] = reason | ||
| else: | ||
| raise TypeError(param) | ||
|
|
||
| def check_params(self, signature, *args, **kwargs): | ||
| binding = signature.bind(*args, **kwargs) | ||
| bound = collections.OrderedDict(binding.arguments, **binding.kwargs) | ||
| return [param for param in bound if param in self.messages] | ||
|
|
||
| def warn_messages(self, messages): | ||
| for message in messages: | ||
| warnings.warn(message, category=self.category, stacklevel=3) | ||
|
|
||
| def __call__(self, f): | ||
| signature = inspect.signature(f) | ||
|
|
||
| @functools.wraps(f) | ||
| def wrapper(*args, **kwargs): | ||
| invalid_params = self.check_params(signature, *args, **kwargs) | ||
| self.warn_messages([self.messages[param] for param in invalid_params]) | ||
| return f(*args, **kwargs) | ||
|
|
||
| return wrapper | ||
|
|
||
|
|
||
| deprecated_params = DeprecatedParams |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is primarily about the API lifecycle, deprecation is just one aspect:
would seem more fitting.
I assume the decorators are additive? We should spell that out explicitly, so agents know what we expect them to do.
Should we also add explicitly that agents remind us to systematically add the
versionaddedandversionchangeddecorators in the future? I imagine this will easily slip if there is no automated mechanism. Less desirable (IMO) alternative: spell out that theversionaddedandversionchangeddecorators are optional, worded in a way that ensures we achieve uniform behavior over different agents or agent versions.