Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .lintrunner.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1167,7 +1167,6 @@ exclude_patterns = [
'aten/src/ATen/native/[a-pA-P]*/**',
'aten/src/ATen/[a-mA-M]*/**',
'test/**',
'test/test_*',
'test/[a-hA-h]*/**',
'test/distributed/**',
'torch/_*/**',
Expand Down
16 changes: 8 additions & 8 deletions test/test_autograd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4129,7 +4129,7 @@ def backward(self, grad_output):
self.assertIsNone(y.grad_fn)

def test_backward_copy(self):
# This tests checks backward engine for a very subtle bug that appreared
# This tests checks backward engine for a very subtle bug that appeared
# in one of the initial versions of autograd. Gradients tensors were
# simply stored in lists while the function waited for all its gradients
# to be computed. However, sometimes an output was used multiple times,
Expand Down Expand Up @@ -4312,7 +4312,7 @@ def backward(ctx, grad_output):
ctx.output_var.sum().backward()
return ctx.x.grad * grad_output

# Reentrant starts on CPU thread, finishs on GPU thread
# Reentrant starts on CPU thread, finishes on GPU thread
x = torch.randn(2, 2, requires_grad=True)
out = Reenter.apply(x)
out.sum().backward()
Expand Down Expand Up @@ -10728,7 +10728,7 @@ def get_tensor_and_weak_ref():
dual = fwAD.make_dual(foo, tangent)
self.assertFalse(tangent_ref.expired())

# Make sure that the tangent we provided has been re-used as is
# Make sure that the tangent we provided has been reused as is
self.assertTrue(fwAD.unpack_dual(dual)[1] is tangent)

# Make sure that dual is keeping the tangent alive
Expand Down Expand Up @@ -11087,7 +11087,7 @@ def test_advanced_packing_unpacking(self):
self.assertEqual(
dual_tangent.storage().data_ptr(), bar.storage().data_ptr()
)
# And the tangent is actually re-used as-is so it is still the same Tensor
# And the tangent is actually reused as-is so it is still the same Tensor
self.assertIs(dual_tangent, bar)

# Ensure we properly share the version counter
Expand Down Expand Up @@ -11969,19 +11969,19 @@ def backward(ctx, grad_output):
(new_param**2).sum().backward()
return grad_output

# Reentrant starts on GPU thread, finishs on GPU thread
# Reentrant starts on GPU thread, finishes on GPU thread
x = torch.randn(2, 2, device=device, requires_grad=True)
out = ReentrantFunc.apply(x)
out.sum().backward()

# Reentrant starts on CPU thread, finishs on GPU thread
# Reentrant starts on CPU thread, finishes on GPU thread
x = torch.randn(2, 2, requires_grad=True)
# set ReentrantFunc node to GPU to emit tasks to GPU queue
ReentrantFunc._cpu_mode = False
out = ReentrantFunc.apply(x)
out.sum().backward()

# Reentrant starts on GPU thread, finishs on CPU thread
# Reentrant starts on GPU thread, finishes on CPU thread
x = torch.randn(2, 2, device=device, requires_grad=True)
# set ReentrantFunc node to CPU to emit tasks to CPU queue
ReentrantFunc._cpu_mode = True
Expand Down Expand Up @@ -13665,7 +13665,7 @@ def forward(self, x):
y = x * x
if torch.cuda.device_count() >= 2:
# DataParallel is calling the forward in different threads
# without progating TLS, so hooks should not be called here
# without propagating TLS, so hooks should not be called here
_self.assertEqual(len(w), 0)
else:
# DataParallel only uses one thread
Expand Down
4 changes: 2 additions & 2 deletions test/test_binary_ufuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
class TestBinaryUfuncs(TestCase):
# Generic tests for elementwise binary (AKA binary universal (u) functions (funcs))
# TODO: below contiguous tensor results are compared with a variety of noncontiguous results.
# It would be interesting to have the lhs and rhs have different discontiguities.
# It would be interesting to have the lhs and rhs have different discontinuities.

# Helper for comparing torch tensors and NumPy arrays
# TODO: should this or assertEqual also validate that strides are equal?
Expand Down Expand Up @@ -2521,7 +2521,7 @@ def _test_copysign_numpy(a, b):
# Verify Value
self.assertEqual(torch_result, expected)
# Verify Sign
# Use double copysign to verify the correctnes of 0.0 and -0.0, since
# Use double copysign to verify the correctness of 0.0 and -0.0, since
# it always True for self.assertEqual(0.0 == -0.0). So, we use 1 as the
# magnitude to verify the sign between torch and numpy results, elementwise.
# Special case: NaN conversions between FP32 and FP16 is not bitwise
Expand Down
10 changes: 5 additions & 5 deletions test/test_cpp_extensions_jit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ def test_warning(self):
t = torch.rand(2).double()
cpp_tensor_name = r"CPUDoubleType"

# Without error handling, the warnings cannot be catched
# Without error handling, the warnings cannot be caught
warn_mod = torch.utils.cpp_extension.load_inline(
name="warn_mod",
cpp_sources=[source],
Expand Down Expand Up @@ -1065,23 +1065,23 @@ def test_warning(self):
)

with warnings.catch_warnings(record=True) as w:
# Catched with no error should be detected
# Caught with no error should be detected
warn_mod.foo(t, 0)
self.assertEqual(len(w), 1)

# Catched with cpp error should also be detected
# Caught with cpp error should also be detected
with self.assertRaisesRegex(TypeError, t.type()):
warn_mod.foo(t, 1)
self.assertEqual(len(w), 2)

# Catched with python error should also be detected
# Caught with python error should also be detected
with self.assertRaisesRegex(
SystemError, "bad argument to internal function"
):
warn_mod.foo(t, 2)
self.assertEqual(len(w), 3)

# Catched with pybind error should also be detected
# Caught with pybind error should also be detected
# Note that there is no type name translation for pybind errors
with self.assertRaisesRegex(KeyError, cpp_tensor_name):
warn_mod.foo(t, 3)
Expand Down
22 changes: 11 additions & 11 deletions test/test_cuda.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ def _test_float32_matmul_precision_get_set_inner(self):
os.environ["TORCH_ALLOW_TF32_CUBLAS_OVERRIDE"]
)
# this is really just checking that the environment variable is respected during testing
# and not overwritten by another function that doesn't revert it to the intitial value
# and not overwritten by another function that doesn't revert it to the initial value
if not skip_tf32_cublas:
self.assertFalse(torch.backends.cuda.matmul.allow_tf32)
self.assertEqual(torch.get_float32_matmul_precision(), "highest")
Expand Down Expand Up @@ -1143,7 +1143,7 @@ def perform_copy():
tmp2 = torch.cuda.FloatTensor(t.size())
tmp2.zero_()
self.assertNotEqual(
tmp2.data_ptr(), ptr[0], msg="allocation re-used to soon"
tmp2.data_ptr(), ptr[0], msg="allocation reused to soon"
)

self.assertEqual(result.tolist(), [1, 2, 3, 4])
Expand All @@ -1154,7 +1154,7 @@ def perform_copy():
torch.cuda.current_stream().synchronize()
with torch.cuda.stream(stream):
tmp3 = torch.cuda.FloatTensor(t.size())
self.assertEqual(tmp3.data_ptr(), ptr[0], msg="allocation not re-used")
self.assertEqual(tmp3.data_ptr(), ptr[0], msg="allocation not reused")

def test_record_stream_on_shifted_view(self):
# See issue #27366
Expand Down Expand Up @@ -1235,20 +1235,20 @@ def test_noncontiguous_pinned_memory(self):
def test_caching_pinned_memory(self):
cycles_per_ms = get_cycles_per_ms()

# check that allocations are re-used after deletion
# check that allocations are reused after deletion
t = torch.FloatTensor([1]).pin_memory()
ptr = t.data_ptr()
del t
t = torch.FloatTensor([1]).pin_memory()
self.assertEqual(t.data_ptr(), ptr, msg="allocation not reused")

# check that the allocation is not re-used if it's in-use by a copy
# check that the allocation is not reused if it's in-use by a copy
gpu_tensor = torch.cuda.FloatTensor([0])
torch.cuda._sleep(int(1000 * cycles_per_ms)) # delay the copy by 1s
gpu_tensor.copy_(t, non_blocking=True)
del t
t = torch.FloatTensor([1]).pin_memory()
self.assertNotEqual(t.data_ptr(), ptr, msg="allocation re-used too soon")
self.assertNotEqual(t.data_ptr(), ptr, msg="allocation reused too soon")
self.assertEqual(list(gpu_tensor), [1])

def test_caching_allocator_record_stream_oom(self):
Expand All @@ -1263,7 +1263,7 @@ def test_caching_allocator_record_stream_oom(self):
x = torch.empty(40 * 1024 * 1024, device="cuda")
with torch.cuda.stream(stream):
y += x
# delays re-use of `x` until after all operations in `stream`
# delays reuse of `x` until after all operations in `stream`
x.record_stream(stream)
del x

Expand Down Expand Up @@ -2970,7 +2970,7 @@ def test_graph_memory_stats_and_use_result_after_destroy_graph(self):
current = postcapture_stats[stat] - precapture_stats[stat]

# There will only ever be one expandable segment in each of the small and large pools. The way the
# bookeeping is done in the allocator means that we never increment the number of segments.
# bookkeeping is done in the allocator means that we never increment the number of segments.
if self.expandable_segments and "segment" in stat:
expected = 0
# These two cases hit an edge case where the PyTorch allocator won't immediately unmap part of an
Expand Down Expand Up @@ -3011,7 +3011,7 @@ def test_graph_memory_stats_and_use_result_after_destroy_graph(self):
current = postdel_stats[stat] - precapture_stats[stat]

# There will only ever be one expandable segment in each of the small and large pools. The way the
# bookeeping is done in the allocator means that we never increment the number of segments.
# bookkeeping is done in the allocator means that we never increment the number of segments.
if self.expandable_segments and "segment" in stat:
expected = 0
# These two cases hit an edge case where the PyTorch allocator won't immediately unmap part of an
Expand Down Expand Up @@ -3648,7 +3648,7 @@ def test_cuda_graph_raw_graph_reset_and_recapture(self):
graph.replay()
self.assertTrue(torch.all(x == 3.0))

# Check that graph capture can succeed after reseting.
# Check that graph capture can succeed after resetting.
graph.reset()

# Don't do x[:] = 0.0 because we want to capture a new address
Expand Down Expand Up @@ -5382,7 +5382,7 @@ def test_mempool_with_allocator(self):
out_2 = torch.randn(nelem_1mb, device="cuda")

# pool now should have 2 segments since the CUDACachingAllocator had
# to make a new 2 MB buffer to accomodate out_2
# to make a new 2 MB buffer to accommodate out_2
self.assertEqual(len(pool.snapshot()), 2)

self.assertEqual(len(pool.snapshot()), 2)
Expand Down
4 changes: 2 additions & 2 deletions test/test_cuda_multigpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ def test_external_streams_multi_device(self):

@unittest.skipIf(not TEST_MULTIGPU, "only one GPU detected")
def test_caching_pinned_memory_multi_gpu(self):
# checks that the events preventing pinned memory from being re-used
# checks that the events preventing pinned memory from being reused
# too early are recorded on the correct GPU
cycles_per_ms = get_cycles_per_ms()

Expand All @@ -982,7 +982,7 @@ def test_caching_pinned_memory_multi_gpu(self):

del t
t = torch.FloatTensor([2]).pin_memory()
self.assertNotEqual(t.data_ptr(), ptr, msg="allocation re-used too soon")
self.assertNotEqual(t.data_ptr(), ptr, msg="allocation reused too soon")

with torch.cuda.device(0):
gpu_tensor0.copy_(t, non_blocking=True)
Expand Down
2 changes: 1 addition & 1 deletion test/test_cuda_nvml_based_avail.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_partial_uuid_resolver(self):
_transform_uuid_to_ordinals(["GPU-9e8d35e3", "GPU-123", "GPU-47"], uuids),
[1],
)
# First ambigous UUID aborts parsing
# First ambiguous UUID aborts parsing
self.assertEqual(
_transform_uuid_to_ordinals(["GPU-9e8d35e3", "GPU-e", "GPU-47"], uuids), [1]
)
Expand Down
2 changes: 1 addition & 1 deletion test/test_cuda_primary_ctx.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_set_device_0(self):
self.assertFalse(torch._C._cuda_hasPrimaryContext(0))
torch.cuda.set_device(0)
if _get_torch_cuda_version() >= (12, 0):
# Now after the device was set, the contex should present in CUDA 12.
# Now after the device was set, the context should present in CUDA 12.
self.assertTrue(torch._C._cuda_hasPrimaryContext(0))
else:
# In CUDA 11 the context should not be created.
Expand Down
4 changes: 2 additions & 2 deletions test/test_custom_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ def g(x):
g(x)

def test_invalid_schemas(self):
# function schmea validation goes through torchgen, so this is just a
# function schema validation goes through torchgen, so this is just a
# basic test.
with self.assertRaisesRegex(AssertionError, "Invalid function schema: foo"):
custom_ops.custom_op(f"{TestCustomOp.test_ns}::foo", "(")
Expand Down Expand Up @@ -2712,7 +2712,7 @@ def backward(ctx, grad):
self.assertEqual(ctx.needs_input_grad, expected)
return list(grad.unbind(0))

# call two applys, do a backward on the first
# call two applies, do a backward on the first
def t():
return torch.randn([], requires_grad=True)

Expand Down
6 changes: 3 additions & 3 deletions test/test_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,12 +734,12 @@ class SleepDataset(Dataset):
def __init__(self, size, sleep_sec):
self.size = size
self.sleep_sec = sleep_sec
self.sleeped = False
self.slept = False

def __getitem__(self, idx):
if not self.sleeped:
if not self.slept:
time.sleep(self.sleep_sec)
self.sleeped = True
self.slept = True
return idx

def __len__(self):
Expand Down
6 changes: 3 additions & 3 deletions test/test_datapipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def operations(df):

class TestDataFramesPipes(TestCase):
"""
Most of test will fail if pandas instaled, but no dill available.
Most of test will fail if pandas installed, but no dill available.
Need to rework them to avoid multiple skips.
"""

Expand Down Expand Up @@ -1887,7 +1887,7 @@ def _non_bool_fn(data):
with self.assertRaises(ValueError):
list(filter_dp)

# Funtional Test: Specify input_col
# Functional Test: Specify input_col
tuple_input_ds = dp.iter.IterableWrapper([(d - 1, d, d + 1) for d in range(10)])

# Single input_col
Expand Down Expand Up @@ -3356,7 +3356,7 @@ def construct_sharded_pipe():
with self.assertRaises(Exception):
dp.apply_sharding(2, 1, sharding_group=SHARDING_PRIORITIES.DEFAULT)

# Test tud.datapipes.iter.grouping.SHARDING_PRIORITIES for backward compatbility
# Test tud.datapipes.iter.grouping.SHARDING_PRIORITIES for backward compatibility
# TODO: Remove this test once tud.datapipes.iter.grouping.SHARDING_PRIORITIES is deprecated
def test_sharding_groups_in_legacy_grouping_package(self):
with self.assertWarnsRegex(
Expand Down
2 changes: 1 addition & 1 deletion test/test_decomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ def __torch_dispatch__(self, func, types, args=(), kwargs=None):
# de-functionalise the graph, as that would break AoTAutograd
# We run the real function *after* the decomposition to make sure that the
# decomposition does not modify any of the inputs in-place. If it does
# real_out should be differen than decom_out so we should catch this
# real_out should be different than decom_out so we should catch this
real_out_unflat = func(*args, **kwargs)
real_out = pytree.tree_leaves(real_out_unflat)

Expand Down
6 changes: 3 additions & 3 deletions test/test_dynamic_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3286,7 +3286,7 @@ def forward(self, arg0_1: "i64[1][1]cpu", arg1_1: "Sym(u1)", arg2_1: "i64[u1][1]
def test_unbacked_reshape2(self):
cnt = CompileCounterWithBackend("inductor")

# This reshape requires a clone when the input is not contiguous and we cant compute strides.
# This reshape requires a clone when the input is not contiguous and we can't compute strides.
# reshape (u2, u3) -> (u0, u1)
def func(x, y):
u0, u1 = y.tolist()
Expand Down Expand Up @@ -3421,7 +3421,7 @@ def make_non_contiguous_tensor(cnt):
def test_invalid_view_unbacked_view(self):
cnt = CompileCounterWithBackend("inductor")

# This view (u2, u3) -> (u0, u1) cant happen in general unless we know that input is contigous or we have
# This view (u2, u3) -> (u0, u1) can't happen in general unless we know that input is contiguous or we have
# hints to to compute strides.
def func(x, y):
u0, u1 = y.tolist()
Expand Down Expand Up @@ -3452,7 +3452,7 @@ def func(y):

func(torch.ones(5, 6, 7, 8))
self.assertEqual(cnt.frame_count, 1)
# it can be dynamic in all dimentions except dim=2
# it can be dynamic in all dimensions except dim=2
func(torch.ones(4, 9, 7, 10))
self.assertEqual(cnt.frame_count, 1)

Expand Down
6 changes: 3 additions & 3 deletions test/test_fake_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def checkType(self, t, device_str, size):

@unittest.skipIf(not RUN_CUDA, "requires cuda")
def test_cuda_initialized(self):
# doesnt error
# doesn't error
with FakeTensorMode():
p = torch.randn(4, 2, requires_grad=True, device="cuda")
x = torch.randn(8, 4, device="cuda")
Expand Down Expand Up @@ -1471,7 +1471,7 @@ def forward(self, arg1, arg2, arg3):
with torch._subclasses.CrossRefFakeMode():
Repro()(*args)
except MetadataMismatchError as e:
# We expect the cross ref to succed for the first output to fail
# We expect the cross ref to succeed for the first output to fail
# for the rng state, see Note [Seed and Offset]
self.assertTrue("output[0]" not in str(e))
if self.__class__.__name__.startswith("PropagateRealTensors"):
Expand Down Expand Up @@ -2327,7 +2327,7 @@ def fn(x, y):
self.assertEqual(len(backend.fw_graphs), 1)
mod = backend.fw_graphs[0]

# Ensure that we see hits everytime
# Ensure that we see hits every time
with FakeTensorMode():
x = torch.randn(6, 4)
y = torch.randn(6, 4)
Expand Down
Loading
Loading