diff --git a/torch/nn/utils/prune.py b/torch/nn/utils/prune.py index c7a0755255b..fa878932423 100644 --- a/torch/nn/utils/prune.py +++ b/torch/nn/utils/prune.py @@ -1315,7 +1315,7 @@ def _compute_nparams_toprune(amount, tensor_size): if isinstance(amount, numbers.Integral): return amount else: - return int(round(amount * tensor_size)) # int needed for Python 2 + return round(amount * tensor_size) def _validate_pruning_dim(t, dim): diff --git a/torchgen/code_template.py b/torchgen/code_template.py index 1f76692e5cd..e8241c65586 100644 --- a/torchgen/code_template.py +++ b/torchgen/code_template.py @@ -12,17 +12,7 @@ from typing import Match, Optional, Sequence, Mapping class CodeTemplate: - # Python 2.7.5 has a bug where the leading (^[^\n\S]*)? does not work, - # workaround via appending another [^\n\S]? inside - - substitution_str = r"(^[^\n\S]*[^\n\S]?)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})" - - # older versions of Python have a bug where \w* does not work, - # so we need to replace with the non-shortened version [a-zA-Z0-9_]* - # https://bugs.python.org/issue18647 - - substitution_str = substitution_str.replace(r"\w", r"[a-zA-Z0-9_]") - + substitution_str = r"(^[^\n\S]*)?\$([^\d\W]\w*|\{,?[^\d\W]\w*\,?})" substitution = re.compile(substitution_str, re.MULTILINE) pattern: str