Browse Source

docs(mge/utils): refine docstring in utils module

GitOrigin-RevId: b2bc163e15
tags/v0.4.0
Megvii Engine Team Xinran Xu 5 years ago
parent
commit
955095c1a9
5 changed files with 27 additions and 20 deletions
  1. +8
    -1
      python_module/megengine/utils/http_download.py
  2. +1
    -1
      python_module/megengine/utils/max_recursion_limit.py
  3. +1
    -1
      python_module/megengine/utils/profile_analyze.py
  4. +16
    -16
      python_module/megengine/utils/profile_analyzer.py
  5. +1
    -1
      python_module/megengine/utils/types.py

+ 8
- 1
python_module/megengine/utils/http_download.py View File

@@ -26,7 +26,14 @@ class HTTPDownloadError(BaseException):
"""The class that represents http request error""" """The class that represents http request error"""




def download_from_url(url, dst, http_read_timeout=120):
def download_from_url(url: str, dst: str, http_read_timeout=120):
"""
Downloads file from given url to ``dst``

:param url: source URL
:param dst: saving path
:param http_read_timeout: how many seconds to wait for data before giving up
"""
dst = os.path.expanduser(dst) dst = os.path.expanduser(dst)
dst_dir = os.path.dirname(dst) dst_dir = os.path.dirname(dst)




+ 1
- 1
python_module/megengine/utils/max_recursion_limit.py View File

@@ -55,6 +55,6 @@ _max_recursion_limit_context_manager = AlternativeRecursionLimit(2 ** 31 - 1)




def max_recursion_limit(): def max_recursion_limit():
r"""set recursion limit to max possible value
r"""Sets recursion limit to the max possible value
""" """
return _max_recursion_limit_context_manager return _max_recursion_limit_context_manager

+ 1
- 1
python_module/megengine/utils/profile_analyze.py View File

@@ -57,7 +57,7 @@ def _tabulate_confluence(tab, **kwargs):




def main(passed_args=None): # pylint: disable=too-many-statements def main(passed_args=None): # pylint: disable=too-many-statements
"""Analyse profile info from :mod:`~.utils.profile_analyzer` .
"""Analyses profile info from :mod:`~.utils.profile_analyzer` .


Run this file with ``--help`` to get more usage. Run this file with ``--help`` to get more usage.
""" """


+ 16
- 16
python_module/megengine/utils/profile_analyzer.py View File

@@ -72,7 +72,7 @@ class OprProfRst:
of corresponding operations""" of corresponding operations"""


def __init__(self, entry: dict): def __init__(self, entry: dict):
"""Opr profiling init, setup name, id, type of opr_info.
"""Opr profiling initialization, which sets up name, type and id of opr_info.


:param entry: profiling json exec_graph items :param entry: profiling json exec_graph items
""" """
@@ -84,7 +84,7 @@ class OprProfRst:
self.footprint = collections.defaultdict(NonExistNum) self.footprint = collections.defaultdict(NonExistNum)


def update_device_prof_info(self, dev_time: dict): def update_device_prof_info(self, dev_time: dict):
"""Update device prof info
"""Updates device profiling info


:param dev_time: device time for single opr, :param dev_time: device time for single opr,
is an attribute of profiling result. is an attribute of profiling result.
@@ -93,7 +93,7 @@ class OprProfRst:
self.time_dict["device"].append(copy.deepcopy(dev_time)) self.time_dict["device"].append(copy.deepcopy(dev_time))


def update_host_prof_info(self, host_time: dict): def update_host_prof_info(self, host_time: dict):
"""Update host profiling info
"""Updates host profiling info


:param host_time: host time for single opr, :param host_time: host time for single opr,
is an attribute of profiling result. is an attribute of profiling result.
@@ -102,7 +102,7 @@ class OprProfRst:
self.time_dict["host"].append(copy.deepcopy(host_time)) self.time_dict["host"].append(copy.deepcopy(host_time))


def update_footprint(self, footprint: dict): def update_footprint(self, footprint: dict):
"""Update opr footprint
"""Updates opr footprint


:param footprint: footprint for single opr, :param footprint: footprint for single opr,
is an attribute of profiling result. is an attribute of profiling result.
@@ -128,7 +128,7 @@ class Record:
] ]


def __init__(self, time: float, info: dict, footprint: dict): def __init__(self, time: float, info: dict, footprint: dict):
"""Init single record
"""Initializes single record


:param time: opr running time, evaluated by applying users providing :param time: opr running time, evaluated by applying users providing
function to OprProfRst. function to OprProfRst.
@@ -153,7 +153,7 @@ class Record:
self.opr_id = int(self.opr_id) self.opr_id = int(self.opr_id)


def get_column_by_name(self, name: str = None): def get_column_by_name(self, name: str = None):
"""extract column value by its column name
"""extracts column value by its column name


:param name: column name, None for time. :param name: column name, None for time.
""" """
@@ -165,7 +165,7 @@ class Record:


class ProfileAnalyzer: class ProfileAnalyzer:
def __init__(self, obj: dict, opr_filter: Callable = lambda opr, inp, out: True): def __init__(self, obj: dict, opr_filter: Callable = lambda opr, inp, out: True):
"""initialize ProfileAnalyzer
"""Initializes ProfileAnalyzer


:param obj: dict dumped from json str. :param obj: dict dumped from json str.
:param opr_filter: function that filter oprs. :param opr_filter: function that filter oprs.
@@ -202,12 +202,12 @@ class ProfileAnalyzer:
def _aggregate( def _aggregate(
self, records: List[Record], aop: Union[str, Callable], atype: Optional[str] self, records: List[Record], aop: Union[str, Callable], atype: Optional[str]
) -> List[Record]: ) -> List[Record]:
"""aggragate operation
"""Aggregate operation


:param records: records that selected:
:param aop: aggragate operation, if aop is str, we would replace it
:param records: selected records
:param aop: aggregate operation, if aop is str, we would replace it
with associated numpy function wth aop name" with associated numpy function wth aop name"
:param atype: the type aggragte by, None for aggragte all into single
:param atype: the type aggregated by, None for aggregating all into single
record. record.
""" """
if aop is None: if aop is None:
@@ -304,7 +304,7 @@ class TimeFuncHelper:


@staticmethod @staticmethod
def _eval_time(prof_type, end_key, func, opr_prof): def _eval_time(prof_type, end_key, func, opr_prof):
"""eval time
"""Eval time


:type prof_type: str :type prof_type: str
:param prof_type: 'host' or 'device' :param prof_type: 'host' or 'device'
@@ -338,7 +338,7 @@ class TimeFuncHelper:
def _min_start( def _min_start(
prof_type, end_key, func, opr_prof prof_type, end_key, func, opr_prof
): # pylint: disable=unused-argument ): # pylint: disable=unused-argument
"""eval time
"""Eval minimum start time


:type prof_type: str :type prof_type: str
:param prof_type: 'host' or 'device' :param prof_type: 'host' or 'device'
@@ -360,7 +360,7 @@ class TimeFuncHelper:
def min_start_func( def min_start_func(
prof_type: str, end_key: str, func: Callable prof_type: str, end_key: str, func: Callable
) -> float: # pylint: disable=unused-argument ) -> float: # pylint: disable=unused-argument
"""Eval oprerator profile time with ``np.min``.
"""Eval oprerator profile min start time


:param prof_type: 'host' or 'device' :param prof_type: 'host' or 'device'
:param end_key: 'kern' or 'end' :param end_key: 'kern' or 'end'
@@ -371,7 +371,7 @@ class TimeFuncHelper:


@staticmethod @staticmethod
def _max_end(prof_type, end_key, func, opr_prof): # pylint: disable=unused-argument def _max_end(prof_type, end_key, func, opr_prof): # pylint: disable=unused-argument
"""eval time
"""Eval maximum end time


:type prof_type: str :type prof_type: str
:param prof_type: 'host' or 'device' :param prof_type: 'host' or 'device'
@@ -391,7 +391,7 @@ class TimeFuncHelper:


@staticmethod @staticmethod
def max_end_func(prof_type: str, end_key: str, func: Callable) -> float: def max_end_func(prof_type: str, end_key: str, func: Callable) -> float:
"""Eval max end time
"""Eval oprerator profile max end time


:param prof_type: 'host' or 'device' :param prof_type: 'host' or 'device'
:param end_key: 'kern' or 'end' :param end_key: 'kern' or 'end'


+ 1
- 1
python_module/megengine/utils/types.py View File

@@ -11,7 +11,7 @@ import functools




def get_ndtuple(value, *, n, allow_zero=True): def get_ndtuple(value, *, n, allow_zero=True):
r""" convert possibly 1D tuple to nd tuple
r"""Converts possibly 1D tuple to nd tuple


:type allow_zero: bool :type allow_zero: bool
:param allow_zero: whether to allow zero tuple value""" :param allow_zero: whether to allow zero tuple value"""


Loading…
Cancel
Save