-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
2024-11-08 nightly release (1fcd5e1)
- Loading branch information
pytorchbot
committed
Nov 8, 2024
1 parent
4686780
commit 4c2507f
Showing
21 changed files
with
754 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from torch.testing._internal.common_utils import TestCase | ||
from torchdata.nodes.adapters import IterableWrapper | ||
from torchdata.nodes.base_node import BaseNodeIterator | ||
|
||
from .utils import run_test_save_load_state | ||
|
||
|
||
class TestBaseNode(TestCase): | ||
def test_started_finished(self) -> None: | ||
x = IterableWrapper(range(10)) | ||
for _ in range(3): # test multi-epoch | ||
it = iter(x) | ||
self.assertIsInstance(it, BaseNodeIterator) | ||
self.assertFalse(it.started()) | ||
self.assertFalse(it.finished()) | ||
|
||
for _ in it: | ||
self.assertTrue(it.started()) | ||
self.assertFalse(it.finished()) | ||
|
||
self.assertTrue(it.started()) | ||
self.assertTrue(it.finished()) | ||
|
||
def test_save_load_state(self): | ||
run_test_save_load_state(self, IterableWrapper(range(10)), 5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from torch.testing._internal.common_utils import TestCase | ||
from torchdata.nodes.adapters import IterableWrapper | ||
from torchdata.nodes.base_node import BaseNodeIterator | ||
from torchdata.nodes.snapshot_store import DequeSnapshotStore | ||
|
||
from .utils import run_test_save_load_state | ||
|
||
|
||
class TestDequeSnapshotStore(TestCase): | ||
def test_snapshot_store(self) -> None: | ||
store = DequeSnapshotStore() | ||
store.append({"a": 1}, 0) | ||
store.append({"a": 2}, 10) | ||
|
||
self.assertEqual(len(store._deque), 2) | ||
|
||
val = store.pop_version(0) | ||
self.assertEqual(val, {"a": 1}) | ||
self.assertEqual(len(store._deque), 1) | ||
val = store.pop_version(1) | ||
self.assertIsNone(val) | ||
self.assertEqual(len(store._deque), 1) | ||
val = store.pop_version(7) | ||
self.assertIsNone(val) | ||
self.assertEqual(len(store._deque), 1) | ||
val = store.pop_version(10) | ||
self.assertEqual(val, {"a": 2}) | ||
self.assertEqual(len(store._deque), 0) | ||
|
||
val = store.pop_version(11) | ||
self.assertIsNone(val) | ||
self.assertEqual(len(store._deque), 0) | ||
|
||
with self.assertRaisesRegex(ValueError, "is not strictly greater than"): | ||
store.append({"a": 3}, 3) | ||
|
||
self.assertEqual(len(store._deque), 0) | ||
|
||
with self.assertRaisesRegex(ValueError, "is not strictly greater than"): | ||
store.append({"a": 4}, 10) | ||
self.assertEqual(len(store._deque), 0) | ||
|
||
store.append({"a": 4}, 11) | ||
store.append({"a": 5}, 19) | ||
val = store.pop_version(19) | ||
self.assertEqual(val, {"a": 5}) | ||
self.assertEqual(len(store._deque), 0) |
Oops, something went wrong.