[BE] fix typos in torchgen/ (#156083)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/156083
Approved by: https://github.com/jingsh
ghstack dependencies: #156079, #156082
This commit is contained in:
Xuehai Pan
2025-06-18 00:11:01 +08:00
committed by PyTorch MergeBot
parent a69785b3ec
commit b020971e78
17 changed files with 21 additions and 22 deletions

View File

@ -1165,7 +1165,6 @@ exclude_patterns = [
'scripts/**', 'scripts/**',
'test/**', 'test/**',
'torch/**', 'torch/**',
'torchgen/**',
] ]
init_command = [ init_command = [
'python3', 'python3',

View File

@ -89,7 +89,7 @@ context = AHContext()
context.add_feature("m", mat1.shape[0]) context.add_feature("m", mat1.shape[0])
context.add_feature("k", mat1.shape[1]) context.add_feature("k", mat1.shape[1])
# adding a categorical feture # adding a categorical feature
context.add_feature("mat1_dtype", mat1.dtype, is_categorical=True) context.add_feature("mat1_dtype", mat1.dtype, is_categorical=True)
``` ```

View File

@ -18,7 +18,7 @@ def transpose_tensors(p_transpose_both: float = 0.05) -> tuple[bool, bool]:
def fits_in_memory(dtype: Any, m: int, k: int, n: int) -> Any: def fits_in_memory(dtype: Any, m: int, k: int, n: int) -> Any:
threshold_memory = torch.cuda.get_device_properties(0).total_memory / 4 threshold_memory = torch.cuda.get_device_properties(0).total_memory / 4
# dividing by 4 beause we otherwise sometimes run out of memory, I assume because # dividing by 4 because we otherwise sometimes run out of memory, I assume because
# inductor creates copies of tensors for benchmarking? # inductor creates copies of tensors for benchmarking?
return dtype.itemsize * (m * k + k * n + m * n) < threshold_memory return dtype.itemsize * (m * k + k * n + m * n) < threshold_memory

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
# this script makes it easy parallize collecting data across using multiple GPUs # This script makes it easy to parallelize data collection across multiple GPUs
# Check if tmux is installed # Check if tmux is installed
if ! command -v tmux &> /dev/null; then if ! command -v tmux &> /dev/null; then

View File

@ -12,7 +12,7 @@ MODE=$1
# !!! SPECIFY THE GPUs THAT YOU WANT TO USE HERE !!! # !!! SPECIFY THE GPUs THAT YOU WANT TO USE HERE !!!
GPU_DEVICE_IDS="4,5" GPU_DEVICE_IDS="4,5"
# !!! SPECIFY THE CONDA ENVIRONEMNT THAT YOU WANT TO BE ACTIVATED HERE !!! # !!! SPECIFY THE CONDA ENVIRONMENT THAT YOU WANT TO BE ACTIVATED HERE !!!
CONDA_ENV=heuristic-pr CONDA_ENV=heuristic-pr
NUM_SAMPLES=2000 NUM_SAMPLES=2000

View File

@ -12,7 +12,7 @@ MODE=$1
# !!! SPECIFY THE GPUs THAT YOU WANT TO USE HERE !!! # !!! SPECIFY THE GPUs THAT YOU WANT TO USE HERE !!!
GPU_DEVICE_IDS="4,5" GPU_DEVICE_IDS="4,5"
# !!! SPECIFY THE CONDA ENVIRONEMNT THAT YOU WANT TO BE ACTIVATED HERE !!! # !!! SPECIFY THE CONDA ENVIRONMENT THAT YOU WANT TO BE ACTIVATED HERE !!!
CONDA_ENV=heuristic-pr CONDA_ENV=heuristic-pr
NUM_SAMPLES=2000 NUM_SAMPLES=2000

View File

@ -93,7 +93,7 @@ class ForwardDerivative:
# This is only used by inplace operations # This is only used by inplace operations
required_original_self_value: bool required_original_self_value: bool
# If this formula is specified in derivatives.yaml or if we are re-using the # If this formula is specified in derivatives.yaml or if we are reusing the
# out of place formula for inplace # out of place formula for inplace
is_reusing_outplace_formula: bool is_reusing_outplace_formula: bool
@ -632,7 +632,7 @@ def match_differentiability_info(
info_dict = non_functional_info_by_signature[f_sig] info_dict = non_functional_info_by_signature[f_sig]
# See https://github.com/pytorch/pytorch/pull/76320/files#r874816389 # See https://github.com/pytorch/pytorch/pull/76320/files#r874816389
assert not any( assert not any(
any("self" in str(inpt.nctype.name) for inpt in info.all_saved_inputs) any("self" in str(input.nctype.name) for input in info.all_saved_inputs)
for info in info_dict.values() for info in info_dict.values()
), f"""\ ), f"""\
Attempted to convert a derivative formula for a mutable operator Attempted to convert a derivative formula for a mutable operator
@ -699,7 +699,7 @@ Attempted to convert a derivative formula for a mutable operator
# we make sure that the original value of the input that is being modified inplace (self_p) is # we make sure that the original value of the input that is being modified inplace (self_p) is
# not used in the formula. Note that the formula can use "original_self_p" here and that would # not used in the formula. Note that the formula can use "original_self_p" here and that would
# trigger a clone of the original input. # trigger a clone of the original input.
# - If we are re-using the out of place formula (is_exact_match == False) then we replace every # - If we are reusing the out of place formula (is_exact_match == False) then we replace every
# occurrence of self_p and self_t by original_self_p and original_self_t. These will be # occurrence of self_p and self_t by original_self_p and original_self_t. These will be
# populated by cloned version of the original input (either the clone done by the backward AD # populated by cloned version of the original input (either the clone done by the backward AD
# logic if self is also used in a backward formula or a special clone that we add). # logic if self is also used in a backward formula or a special clone that we add).

View File

@ -127,7 +127,7 @@ def valuetype_type(
# Translation of types occurring in JIT arguments to a C++ argument type. # Translation of types occurring in JIT arguments to a C++ argument type.
# If remove_non_owning_ref_types is set, we'll guarantee that the outputed CType is not a non-owning reference type. # If remove_non_owning_ref_types is set, we'll guarantee that the output CType is not a non-owning reference type.
# For example, we'll return std::vector<int> instead of IntArrayRef. # For example, we'll return std::vector<int> instead of IntArrayRef.
# See Note [translation from C++ reference to value types] # See Note [translation from C++ reference to value types]
def argumenttype_type( def argumenttype_type(

View File

@ -49,7 +49,7 @@ class CppSignature:
# Is this a fallback C++ binding? Fallback bindings are enabled by # Is this a fallback C++ binding? Fallback bindings are enabled by
# manual_cpp_binding: True and are alternate, non-public API that # manual_cpp_binding: True and are alternate, non-public API that
# lets manual C++ binding implementors access the binding that would # lets manual C++ binding implementers access the binding that would
# have been automatically generated # have been automatically generated
fallback_binding: bool = False fallback_binding: bool = False

View File

@ -12,7 +12,7 @@ def torch_api_key_word_prefix(bankend_index: BackendIndex) -> str:
if bankend_index.external: if bankend_index.external:
return "" return ""
# Although Intel GPU ATen library is out-of-tree, it still utilizes torchgen to produce structrued # Although Intel GPU ATen library is out-of-tree, it still utilizes torchgen to produce structured
# kernels. Regarding these produced structured kernels, they should be visible for the Intel GPU ATen # kernels. Regarding these produced structured kernels, they should be visible for the Intel GPU ATen
# library. Therefore, we need to add "TORCH_XPU_API" prefix to these structured kernels, # library. Therefore, we need to add "TORCH_XPU_API" prefix to these structured kernels,
# rather than "TORCH_API". Because the semantic of "TORCH_API" is "hidden" for out-of-tree backends. # rather than "TORCH_API". Because the semantic of "TORCH_API" is "hidden" for out-of-tree backends.

View File

@ -764,7 +764,7 @@ resize_out(out, sizes, strides, options);
# we generate CompositeExplicitAutogradNonFunctional implementations of functional and inplace # we generate CompositeExplicitAutogradNonFunctional implementations of functional and inplace
# based on the out implementation. But in fact, out is definable by # based on the out implementation. But in fact, out is definable by
# functional too (just not very efficiently), and this is honestly the # functional too (just not very efficiently), and this is honestly the
# MORE likely situation for a backend implementor. How do we pick? # MORE likely situation for a backend implementer. How do we pick?
# Well, taking a page from Haskell type classes and default methods, # Well, taking a page from Haskell type classes and default methods,
# we could conceivably register a circular definition (out in terms # we could conceivably register a circular definition (out in terms
# of functional, and functional in terms of out) and just require # of functional, and functional in terms of out) and just require
@ -777,7 +777,7 @@ resize_out(out, sizes, strides, options);
and f.func.kind() is SchemaKind.out and f.func.kind() is SchemaKind.out
): ):
# Never generate a default implementation for out, that's what you # Never generate a default implementation for out, that's what you
# have to define as a backend implementor # have to define as a backend implementer
return None return None
# Note [Direct dispatch bindings] # Note [Direct dispatch bindings]

View File

@ -42,7 +42,7 @@ if TYPE_CHECKING:
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
# NB: not bothering to generate dispatch stub forward declaration in header, # NB: not bothering to generate dispatch stub forward declaration in header,
# we can just paste it whereever necessary # we can just paste it wherever necessary
# TODO: use BackendIndex # TODO: use BackendIndex
# dispatch_key: DispatchKey # only CPU/CUDA right now # dispatch_key: DispatchKey # only CPU/CUDA right now

View File

@ -506,7 +506,7 @@ def static_dispatch(
) -> str: ) -> str:
""" """
For a given `NativeFunction`, find out the corresponding backend and dispatch to it. If more than one For a given `NativeFunction`, find out the corresponding backend and dispatch to it. If more than one
backends exsit, fallback to static dispatch by determining dispatch key from inputs. backends exist, fallback to static dispatch by determining dispatch key from inputs.
Arguments: Arguments:
sig: A CppSignature or DispatcherSignature for this native function we want to use. sig: A CppSignature or DispatcherSignature for this native function we want to use.
f: NativeFunction to generate static dispatch. f: NativeFunction to generate static dispatch.
@ -2611,7 +2611,7 @@ def gen_source_files(
# but they could theoretically be called from user code (I added these kernels for completeness, # but they could theoretically be called from user code (I added these kernels for completeness,
# since the ops are part of the public API). # since the ops are part of the public API).
# (2) A derivative formula for every {view}_copy operator # (2) A derivative formula for every {view}_copy operator
# {view}_copy operators can re-use the same derivative formulas as their {view} op counterparts, # {view}_copy operators can reuse the same derivative formulas as their {view} op counterparts,
# so rather than stamping all of the entries out in derivatives.yaml, # so rather than stamping all of the entries out in derivatives.yaml,
# we codegen them in. # we codegen them in.
# This is similar to how autograd codegen doesn't require inplace ops to have a derivatives.yaml entry. # This is similar to how autograd codegen doesn't require inplace ops to have a derivatives.yaml entry.

View File

@ -198,7 +198,7 @@ def is_tensor_like(a: Argument | TensorOptionsArguments | SelfArgument) -> bool:
# We need to wrap / unwrap various arguments from the op in the functionalization kernels. # We need to wrap / unwrap various arguments from the op in the functionalization kernels.
# Some op schemas include non-owning types though (like TensorList), # Some op schemas include non-owning types though (like TensorList),
# and when we unwrap them we expect to get out an owning type!. # and when we unwrap them we expect to get out an owning type!.
# We also return a lambda that tells you how to conver the non-owning type argument into the owning type. # We also return a lambda that tells you how to convert the non-owning type argument into the owning type.
def get_owning_type(t: CType) -> tuple[CType, Callable[[str], str]]: def get_owning_type(t: CType) -> tuple[CType, Callable[[str], str]]:
if t == BaseCType(tensorListT): if t == BaseCType(tensorListT):
return VectorCType(BaseCType(tensorT)), lambda x: f"{x}.vec()" return VectorCType(BaseCType(tensorT)), lambda x: f"{x}.vec()"
@ -441,7 +441,7 @@ def emit_view_functionalization_body(
// This function adds the above view meta to the current tensor and replays them off the base, // This function adds the above view meta to the current tensor and replays them off the base,
// mutating the size/stride info of the current FunctionalTensorWrapper. // mutating the size/stride info of the current FunctionalTensorWrapper.
// Because of this, we need to make sure to run the reference shape function above, // Because of this, we need to make sure to run the reference shape function above,
// BEFORE doing this (otherwise we'll end up runnin the reference function using the wrong sizes/strides) // BEFORE doing this (otherwise we'll end up running the reference function using the wrong sizes/strides)
at::functionalization::impl::mutate_view_meta({view_tensor_name}, view_meta); at::functionalization::impl::mutate_view_meta({view_tensor_name}, view_meta);
// See Note [Propagating strides in the functionalization pass] // See Note [Propagating strides in the functionalization pass]
// XLA/LTC don't implement the logic to propagate strides correctly, so we need to rely // XLA/LTC don't implement the logic to propagate strides correctly, so we need to rely

View File

@ -47,7 +47,7 @@ class TypeGen:
all_base_tys = [TypeGen.from_example(x) for x in obj] all_base_tys = [TypeGen.from_example(x) for x in obj]
if len(set(all_base_tys)) > 1: if len(set(all_base_tys)) > 1:
raise RuntimeError( raise RuntimeError(
f"Cannot generate schema for a seqeunce of args of heterogeneous types: {all_base_tys}. " f"Cannot generate schema for a sequence of args of heterogeneous types: {all_base_tys}. "
"Consider unpacking the argument and give proper names to them if possible " "Consider unpacking the argument and give proper names to them if possible "
"instead of using *args." "instead of using *args."
) )

View File

@ -593,7 +593,7 @@ class NativeFunction:
has_composite_explicit_autograd_non_functional_kernel: bool has_composite_explicit_autograd_non_functional_kernel: bool
# Tags are used to describe semantic information about (groups of) operators, # Tags are used to describe semantic information about (groups of) operators,
# That aren't easily inferrable directly from the operator's schema. # That aren't easily inferable directly from the operator's schema.
tags: set[str] tags: set[str]
# NB: The benefit of defining a dataclass is that we automatically get # NB: The benefit of defining a dataclass is that we automatically get

View File

@ -102,7 +102,7 @@ def gen_serialized_decompisitions() -> str:
output_strs.append(curr_str) output_strs.append(curr_str)
final_output = "" final_output = ""
# Windows compiler doesnt correctly handle adjacent # Windows compiler doesn't correctly handle adjacent
# string literals # string literals
for output_str in output_strs: for output_str in output_strs:
start = '+ std::string(R"=====(' start = '+ std::string(R"=====('