Skip to content

Commit

Permalink
Merge branch 'master' into feat_artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
awaelchli committed May 27, 2021
2 parents 1faa389 + 04dcb17 commit e0f302f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `ddp_fully_sharded` support ([#7487](https://github.com/PyTorchLightning/pytorch-lightning/pull/7487))


- Added `__len__` to `IndexBatchSamplerWrapper` ([#7681](https://github.com/PyTorchLightning/pytorch-lightning/pull/7681))


- Added `should_rank_save_checkpoint` property to Training Plugins ([#7684](https://github.com/PyTorchLightning/pytorch-lightning/pull/7684))


Expand Down
3 changes: 3 additions & 0 deletions pytorch_lightning/overrides/distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def __iter__(self) -> Iterator[List[int]]:
self.batch_indices = batch
yield batch

def __len__(self) -> int:
return len(self._sampler)

@property
def drop_last(self) -> bool:
return self._sampler.drop_last
Expand Down
13 changes: 13 additions & 0 deletions tests/overrides/test_distributed.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from collections.abc import Iterable

import pytest
from torch.utils.data import BatchSampler, SequentialSampler

from pytorch_lightning import seed_everything
from pytorch_lightning.overrides.distributed import IndexBatchSamplerWrapper, UnrepeatedDistributedSampler
from pytorch_lightning.utilities.data import has_len


@pytest.mark.parametrize("shuffle", [False, True])
Expand Down Expand Up @@ -54,3 +57,13 @@ def test_index_batch_sampler(tmpdir):

for batch in index_batch_sampler:
assert index_batch_sampler.batch_indices == batch


def test_index_batch_sampler_methods():
dataset = range(15)
sampler = SequentialSampler(dataset)
batch_sampler = BatchSampler(sampler, 3, False)
index_batch_sampler = IndexBatchSamplerWrapper(batch_sampler)

assert isinstance(index_batch_sampler, Iterable)
assert has_len(index_batch_sampler)

0 comments on commit e0f302f

Please sign in to comment.