forked from Lightning-AI/pytorch-lightning
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BoringFabric in tests (Lightning-AI#19364)
- Loading branch information
Showing
7 changed files
with
151 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from typing import Iterator | ||
|
||
import torch | ||
from torch import Tensor | ||
from torch.utils.data import Dataset, IterableDataset | ||
|
||
|
||
class RandomDataset(Dataset): | ||
def __init__(self, size: int, length: int) -> None: | ||
self.len = length | ||
self.data = torch.randn(length, size) | ||
|
||
def __getitem__(self, index: int) -> Tensor: | ||
return self.data[index] | ||
|
||
def __len__(self) -> int: | ||
return self.len | ||
|
||
|
||
class RandomIterableDataset(IterableDataset): | ||
def __init__(self, size: int, count: int) -> None: | ||
self.count = count | ||
self.size = size | ||
|
||
def __iter__(self) -> Iterator[Tensor]: | ||
for _ in range(self.count): | ||
yield torch.randn(self.size) |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.