mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 00:21:07 +01:00
Fixes #112590 Fixed docstring errors in `torch/cuda/memory.py` and `torch/cuda/nvtx.py`. memory.py Before ``` torch/cuda/memory.py:1 at module level: D100: Missing docstring in public module torch/cuda/memory.py:67 in public function `caching_allocator_alloc`: D401: First line should be in imperative mood (perhaps 'Perform', not 'Performs') torch/cuda/memory.py:103 in public function `caching_allocator_delete`: D401: First line should be in imperative mood (perhaps 'Delete', not 'Deletes') torch/cuda/memory.py:122 in public function `set_per_process_memory_fraction`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:148 in public function `empty_cache`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:148 in public function `empty_cache`: D400: First line should end with a period (not 'g') torch/cuda/memory.py:163 in public function `memory_stats`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:163 in public function `memory_stats`: D400: First line should end with a period (not 'a') torch/cuda/memory.py:163 in public function `memory_stats`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:264 in public function `memory_stats_as_nested_dict`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:272 in public function `reset_accumulated_memory_stats`: D401: First line should be in imperative mood (perhaps 'Reset', not 'Resets') torch/cuda/memory.py:292 in public function `reset_peak_memory_stats`: D401: First line should be in imperative mood (perhaps 'Reset', not 'Resets') torch/cuda/memory.py:311 in public function `reset_max_memory_allocated`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:311 in public function `reset_max_memory_allocated`: D400: First line should end with a period (not 'y') torch/cuda/memory.py:311 in public function `reset_max_memory_allocated`: D401: First line should be in imperative mood (perhaps 'Reset', not 'Resets') torch/cuda/memory.py:338 in public function `reset_max_memory_cached`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:338 in public function `reset_max_memory_cached`: D400: First line should end with a period (not 'e') torch/cuda/memory.py:338 in public function `reset_max_memory_cached`: D401: First line should be in imperative mood (perhaps 'Reset', not 'Resets') torch/cuda/memory.py:365 in public function `memory_allocated`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:365 in public function `memory_allocated`: D400: First line should end with a period (not 'n') torch/cuda/memory.py:365 in public function `memory_allocated`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:383 in public function `max_memory_allocated`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:383 in public function `max_memory_allocated`: D400: First line should end with a period (not 'n') torch/cuda/memory.py:383 in public function `max_memory_allocated`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:405 in public function `memory_reserved`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:405 in public function `memory_reserved`: D400: First line should end with a period (not 's') torch/cuda/memory.py:405 in public function `memory_reserved`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:421 in public function `max_memory_reserved`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:421 in public function `max_memory_reserved`: D400: First line should end with a period (not 's') torch/cuda/memory.py:421 in public function `max_memory_reserved`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:443 in public function `memory_cached`: D401: First line should be in imperative mood; try rephrasing (found 'Deprecated') torch/cuda/memory.py:452 in public function `max_memory_cached`: D401: First line should be in imperative mood; try rephrasing (found 'Deprecated') torch/cuda/memory.py:461 in public function `memory_snapshot`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:474 in public function `memory_summary`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:474 in public function `memory_summary`: D400: First line should end with a period (not 'r') torch/cuda/memory.py:474 in public function `memory_summary`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:612 in public function `list_gpu_processes`: D202: No blank lines allowed after function docstring (found 1) torch/cuda/memory.py:612 in public function `list_gpu_processes`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:612 in public function `list_gpu_processes`: D400: First line should end with a period (not 's') torch/cuda/memory.py:612 in public function `list_gpu_processes`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:648 in public function `mem_get_info`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:648 in public function `mem_get_info`: D400: First line should end with a period (not 'n') torch/cuda/memory.py:648 in public function `mem_get_info`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:684 in private function `_record_memory_history`: D202: No blank lines allowed after function docstring (found 1) torch/cuda/memory.py:684 in private function `_record_memory_history`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:684 in private function `_record_memory_history`: D400: First line should end with a period (not 'y') torch/cuda/memory.py:684 in private function `_record_memory_history`: D401: First line should be in imperative mood (perhaps 'Enable', not 'Enables') torch/cuda/memory.py:742 in private function `_snapshot`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:742 in private function `_snapshot`: D401: First line should be in imperative mood (perhaps 'Save', not 'Saves') torch/cuda/memory.py:818 in private function `_dump_snapshot`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:818 in private function `_dump_snapshot`: D401: First line should be in imperative mood (perhaps 'Save', not 'Saves') torch/cuda/memory.py:849 in public function `get_allocator_backend`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:849 in public function `get_allocator_backend`: D400: First line should end with a period (not 'y') torch/cuda/memory.py:849 in public function `get_allocator_backend`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') torch/cuda/memory.py:894 in public method `__init__`: D107: Missing docstring in __init__ torch/cuda/memory.py:904 in public function `change_current_allocator`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:904 in public function `change_current_allocator`: D401: First line should be in imperative mood (perhaps 'Change', not 'Changes') torch/cuda/memory.py:917 in private function `_get_current_allocator`: D401: First line should be in imperative mood (perhaps 'Return', not 'Returns') 58 ``` After ``` torch/cuda/memory.py:151 in public function `empty_cache`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:151 in public function `empty_cache`: D400: First line should end with a period (not 'g') torch/cuda/memory.py:439 in public function `memory_cached`: D401: First line should be in imperative mood; try rephrasing (found 'Deprecated') torch/cuda/memory.py:448 in public function `max_memory_cached`: D401: First line should be in imperative mood; try rephrasing (found 'Deprecated') torch/cuda/memory.py:676 in private function `_record_memory_history`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:676 in private function `_record_memory_history`: D400: First line should end with a period (not 'y') torch/cuda/memory.py:841 in public function `get_allocator_backend`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/memory.py:841 in public function `get_allocator_backend`: D400: First line should end with a period (not 'y') 8 ``` nvtx.py Before ``` torch/cuda/nvtx.py:1 at module level: D100: Missing docstring in public module torch/cuda/nvtx.py:24 in public function `range_push`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:24 in public function `range_push`: D400: First line should end with a period (not 'd') torch/cuda/nvtx.py:35 in public function `range_pop`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:35 in public function `range_pop`: D400: First line should end with a period (not 'e') torch/cuda/nvtx.py:43 in public function `range_start`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:43 in public function `range_start`: D400: First line should end with a period (not 'e') torch/cuda/nvtx.py:81 in public function `range`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:81 in public function `range`: D400: First line should end with a period (not 'g') 9 ``` After ``` torch/cuda/nvtx.py:41 in public function `range_start`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:41 in public function `range_start`: D400: First line should end with a period (not 'e') torch/cuda/nvtx.py:79 in public function `range`: D205: 1 blank line required between summary line and description (found 0) torch/cuda/nvtx.py:79 in public function `range`: D400: First line should end with a period (not 'g') 4 ``` Pull Request resolved: https://github.com/pytorch/pytorch/pull/112751 Approved by: https://github.com/kit1980
92 lines
2.4 KiB
Python
92 lines
2.4 KiB
Python
r"""This package adds support for NVIDIA Tools Extension (NVTX) used in profiling."""
|
|
|
|
from contextlib import contextmanager
|
|
|
|
try:
|
|
from torch._C import _nvtx
|
|
except ImportError:
|
|
|
|
class _NVTXStub:
|
|
@staticmethod
|
|
def _fail(*args, **kwargs):
|
|
raise RuntimeError(
|
|
"NVTX functions not installed. Are you sure you have a CUDA build?"
|
|
)
|
|
|
|
rangePushA = _fail
|
|
rangePop = _fail
|
|
markA = _fail
|
|
|
|
_nvtx = _NVTXStub() # type: ignore[assignment]
|
|
|
|
__all__ = ["range_push", "range_pop", "range_start", "range_end", "mark", "range"]
|
|
|
|
|
|
def range_push(msg):
|
|
"""
|
|
Push a range onto a stack of nested range span. Returns zero-based depth of the range that is started.
|
|
|
|
Args:
|
|
msg (str): ASCII message to associate with range
|
|
"""
|
|
return _nvtx.rangePushA(msg)
|
|
|
|
|
|
def range_pop():
|
|
"""Pop a range off of a stack of nested range spans. Returns the zero-based depth of the range that is ended."""
|
|
return _nvtx.rangePop()
|
|
|
|
|
|
def range_start(msg) -> int:
|
|
"""
|
|
Mark the start of a range with string message. It returns an unique handle
|
|
for this range to pass to the corresponding call to rangeEnd().
|
|
|
|
A key difference between this and range_push/range_pop is that the
|
|
range_start/range_end version supports range across threads (start on one
|
|
thread and end on another thread).
|
|
|
|
Returns: A range handle (uint64_t) that can be passed to range_end().
|
|
|
|
Args:
|
|
msg (str): ASCII message to associate with the range.
|
|
"""
|
|
return _nvtx.rangeStartA(msg)
|
|
|
|
|
|
def range_end(range_id) -> None:
|
|
"""
|
|
Mark the end of a range for a given range_id.
|
|
|
|
Args:
|
|
range_id (int): an unique handle for the start range.
|
|
"""
|
|
_nvtx.rangeEnd(range_id)
|
|
|
|
|
|
def mark(msg):
|
|
"""
|
|
Describe an instantaneous event that occurred at some point.
|
|
|
|
Args:
|
|
msg (str): ASCII message to associate with the event.
|
|
"""
|
|
return _nvtx.markA(msg)
|
|
|
|
|
|
@contextmanager
|
|
def range(msg, *args, **kwargs):
|
|
"""
|
|
Context manager / decorator that pushes an NVTX range at the beginning
|
|
of its scope, and pops it at the end. If extra arguments are given,
|
|
they are passed as arguments to msg.format().
|
|
|
|
Args:
|
|
msg (str): message to associate with the range
|
|
"""
|
|
range_push(msg.format(*args, **kwargs))
|
|
try:
|
|
yield
|
|
finally:
|
|
range_pop()
|