Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Data V2 #3700

Merged
merged 59 commits into from
Feb 26, 2020
Merged

Data V2 #3700

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
0c42cb9
example for feedback
DeNeutoy Jan 30, 2020
5ffedfc
Merge branch 'master' into data-v2
DeNeutoy Feb 19, 2020
80049f8
remove all existing multiprocessing
DeNeutoy Feb 19, 2020
6f58c2a
sneak torch datasets inside DatasetReader
DeNeutoy Feb 19, 2020
1b3ad9a
lint
DeNeutoy Feb 19, 2020
effc445
trainer_v2, We Love To See It
DeNeutoy Feb 19, 2020
9d44ad6
datasets have index_with now, not iterators
DeNeutoy Feb 19, 2020
7e89ea6
use iter, custom collate function in allennlp wrapper
DeNeutoy Feb 19, 2020
883b6d7
we don't even need the data in the trainer anymore
DeNeutoy Feb 19, 2020
56d022a
all trainer tests passing
DeNeutoy Feb 20, 2020
01e12f5
black
DeNeutoy Feb 20, 2020
5aea291
make find learning rate work
DeNeutoy Feb 20, 2020
f026946
update test fixtures to new config
DeNeutoy Feb 20, 2020
5973b50
get train command tests mostly working
DeNeutoy Feb 20, 2020
a23f47a
lazily construct samplers, index lazy datasets
DeNeutoy Feb 20, 2020
a76ea0a
Merge branch 'master' into data-v2
DeNeutoy Feb 20, 2020
ebf3854
update some fixtures
DeNeutoy Feb 20, 2020
57a67e5
evaluate tests passing
DeNeutoy Feb 20, 2020
7d21ed8
all command tests passing
DeNeutoy Feb 20, 2020
24a500c
lint
DeNeutoy Feb 20, 2020
fb13769
update model test case, common and module tests passing
DeNeutoy Feb 20, 2020
ef5187f
fix test interdependence introduced by #3762
DeNeutoy Feb 21, 2020
b1ea845
more test interdependence
DeNeutoy Feb 21, 2020
0231616
tests tests tests
DeNeutoy Feb 21, 2020
01d76bb
remove unnecessary brackets
DeNeutoy Feb 21, 2020
12b6efb
Merge branch 'master' into data-v2
DeNeutoy Feb 21, 2020
859d3ca
update a chunk of the configs
DeNeutoy Feb 21, 2020
c22dee3
fix archival test, couple more configs
DeNeutoy Feb 21, 2020
fe5b470
rm pointless gan test
DeNeutoy Feb 21, 2020
7533c91
more tests passing
DeNeutoy Feb 21, 2020
ad45659
add current state of from params changes
DeNeutoy Feb 21, 2020
f944840
Revert "add current state of from params changes"
DeNeutoy Feb 21, 2020
3b12a2f
Merge branch 'master' into data-v2
DeNeutoy Feb 21, 2020
be1f58c
updated understanding of Lazy
DeNeutoy Feb 21, 2020
ebdabe0
add discussion of None comparison to Lazy
DeNeutoy Feb 21, 2020
8693739
lint
DeNeutoy Feb 21, 2020
b9b0650
it's a hard doc life
DeNeutoy Feb 21, 2020
88314c7
pull samplers into separate file
DeNeutoy Feb 21, 2020
14296a1
more docs updates
DeNeutoy Feb 22, 2020
8a08899
fold in #3812
DeNeutoy Feb 22, 2020
3520280
remove torch dataset
DeNeutoy Feb 22, 2020
0f1d8a4
add example to lazy
DeNeutoy Feb 22, 2020
93e1e89
rename to collate
DeNeutoy Feb 22, 2020
40dd695
no kwargs
DeNeutoy Feb 23, 2020
da3b1b4
Revert "fold in #3812"
DeNeutoy Feb 23, 2020
801a8f5
don't break up dataset
DeNeutoy Feb 23, 2020
007fd0c
add comment to iterable dataset len
DeNeutoy Feb 23, 2020
d00e1a9
Merge branch 'master' into data-v2
DeNeutoy Feb 23, 2020
c066804
improve docstrings, build dataloader using partial_objects
DeNeutoy Feb 23, 2020
61c7b14
flake
DeNeutoy Feb 23, 2020
2b56b14
give dataloader a default implementation
DeNeutoy Feb 24, 2020
354010a
safer default for DataLoader init
DeNeutoy Feb 24, 2020
568291d
more coherent dir structure
DeNeutoy Feb 24, 2020
a016103
update imports
DeNeutoy Feb 24, 2020
47db16a
Merge branch 'master' into data-v2
DeNeutoy Feb 24, 2020
04fdb70
add a test for the BucketBatchSampler
DeNeutoy Feb 24, 2020
d1d5c4a
split bucket sampler into own file, tests
DeNeutoy Feb 24, 2020
5f0c8db
PR comments
DeNeutoy Feb 26, 2020
6f63a53
Merge branch 'master' into data-v2
DeNeutoy Feb 26, 2020
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
Prev Previous commit
Next Next commit
tests tests tests
  • Loading branch information
DeNeutoy committed Feb 21, 2020
commit 02316164339d02bd07688e6a46c96df1e37552e3
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

import torch

from allennlp.data.dataset_readers.dataset_reader import AllennlpDataset
from allennlp.common import Lazy, Params
from allennlp.common.checks import ConfigurationError
from allennlp.common.testing import AllenNlpTestCase
from allennlp.data.iterators import BasicIterator
from allennlp.data.samplers import DataLoader
from allennlp.training import TrainerBase
from allennlp.training.learning_rate_schedulers import LearningRateScheduler, SlantedTriangular
from allennlp.training.optimizers import Optimizer
Expand Down Expand Up @@ -112,15 +113,14 @@ def test_from_params_in_trainer(self):
)
# The method called in the logic below only checks the length of this list, not its
# contents, so this should be safe.
instances = [1] * 40
instances = AllennlpDataset([1] * 40)
optim = self._get_optimizer()
trainer = TrainerBase.from_params(
model=self.model,
optimizer=Lazy(lambda **kwargs: optim),
serialization_dir=self.TEST_DIR,
params=params,
iterator=BasicIterator(batch_size=10),
train_data=instances,
data_loader=DataLoader(instances, batch_size=10),
)
assert isinstance(trainer._learning_rate_scheduler, SlantedTriangular)

Expand Down Expand Up @@ -150,8 +150,7 @@ def test_from_params_in_trainer(self):
optimizer=Lazy(lambda **kwargs: optim),
serialization_dir=self.TEST_DIR,
params=params,
iterator=BasicIterator(batch_size=10),
train_data=instances,
data_loader=DataLoader(instances, batch_size=10),
)
assert trainer._learning_rate_scheduler.num_epochs == 3

Expand Down
7 changes: 3 additions & 4 deletions allennlp/tests/training/optimizer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from allennlp.common.testing import AllenNlpTestCase
from allennlp.data import Vocabulary
from allennlp.data.dataset_readers import SequenceTaggingDatasetReader
from allennlp.data.iterators import BasicIterator
from allennlp.data.samplers import DataLoader
from allennlp.models.simple_tagger import SimpleTagger
from allennlp.training import Trainer
from allennlp.training.optimizers import Optimizer
Expand Down Expand Up @@ -90,6 +90,5 @@ def test_can_optimise_model_with_dense_and_sparse_params(self):
optimizer_params = Params({"type": "dense_sparse_adam"})
parameters = [[n, p] for n, p in self.model.named_parameters() if p.requires_grad]
optimizer = Optimizer.from_params(model_parameters=parameters, params=optimizer_params)
iterator = BasicIterator(2)
iterator.index_with(self.vocab)
Trainer(self.model, optimizer, iterator, self.instances).train()
self.instances.index_with(self.vocab)
Trainer(self.model, optimizer, DataLoader(self.instances, 2)).train()
51 changes: 25 additions & 26 deletions allennlp/tests/training/trainer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_trainer_can_resume_training_for_exponential_moving_average(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=1,
serialization_dir=self.TEST_DIR,
moving_average=moving_average,
Expand All @@ -168,7 +168,7 @@ def test_trainer_can_resume_training_for_exponential_moving_average(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
moving_average=new_moving_average,
Expand All @@ -190,7 +190,7 @@ def test_metric_only_considered_best_so_far_when_strictly_better_than_those_befo
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_metric_only_considered_best_so_far_when_strictly_better_than_those_befo
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand Down Expand Up @@ -257,7 +257,7 @@ def test_should_stop_early_with_increasing_metric(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand All @@ -280,7 +280,7 @@ def test_should_stop_early_with_flat_lining_metric(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand All @@ -293,7 +293,7 @@ def test_should_stop_early_with_flat_lining_metric(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand All @@ -307,7 +307,7 @@ def test_should_stop_early_with_decreasing_metric(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
patience=5,
Expand All @@ -333,7 +333,7 @@ def test_should_stop_early_with_early_stopping_disabled(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=100,
patience=None,
validation_metric="+test",
Expand All @@ -347,7 +347,7 @@ def test_should_stop_early_with_early_stopping_disabled(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=100,
patience=None,
validation_metric="-test",
Expand All @@ -368,7 +368,7 @@ def test_should_stop_early_with_invalid_patience(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=100,
patience=patience,
validation_metric="+test",
Expand All @@ -385,7 +385,7 @@ def test_trainer_can_run_and_resume_with_momentum_scheduler(self):
data_loader=self.data_loader,
momentum_scheduler=scheduler,
validation_metric="-loss",
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=4,
serialization_dir=self.TEST_DIR,
)
Expand All @@ -401,7 +401,7 @@ def test_trainer_can_run_and_resume_with_momentum_scheduler(self):
data_loader=self.data_loader,
momentum_scheduler=new_scheduler,
validation_metric="-loss",
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=6,
serialization_dir=self.TEST_DIR,
)
Expand All @@ -418,7 +418,7 @@ def test_trainer_can_run_with_lr_scheduler(self):
data_loader=self.data_loader,
learning_rate_scheduler=lr_scheduler,
validation_metric="-loss",
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=2,
)
trainer.train()
Expand All @@ -430,7 +430,7 @@ def test_trainer_can_resume_with_lr_scheduler(self):
optimizer=self.optimizer,
data_loader=self.data_loader,
learning_rate_scheduler=lr_scheduler,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=2,
serialization_dir=self.TEST_DIR,
)
Expand All @@ -442,7 +442,7 @@ def test_trainer_can_resume_with_lr_scheduler(self):
optimizer=self.optimizer,
data_loader=self.data_loader,
learning_rate_scheduler=new_lr_scheduler,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=4,
serialization_dir=self.TEST_DIR,
)
Expand Down Expand Up @@ -503,7 +503,7 @@ def test_trainer_saves_metrics_every_epoch(self):
model=self.model,
optimizer=self.optimizer,
data_loader=self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=5,
serialization_dir=self.TEST_DIR,
num_serialized_models_to_keep=3,
Expand Down Expand Up @@ -620,7 +620,7 @@ def test_trainer_saves_and_loads_best_validation_metrics_correctly_1(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="-loss",
num_epochs=1,
serialization_dir=self.TEST_DIR,
Expand All @@ -638,7 +638,7 @@ def test_trainer_saves_and_loads_best_validation_metrics_correctly_1(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="-loss",
num_epochs=2,
serialization_dir=self.TEST_DIR,
Expand All @@ -659,7 +659,7 @@ def test_trainer_saves_and_loads_best_validation_metrics_correctly_2(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="+loss",
num_epochs=1,
serialization_dir=self.TEST_DIR,
Expand All @@ -678,7 +678,7 @@ def test_trainer_saves_and_loads_best_validation_metrics_correctly_2(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="+loss",
num_epochs=2,
serialization_dir=self.TEST_DIR,
Expand All @@ -701,8 +701,7 @@ def test_restored_training_returns_best_epoch_metrics_even_if_no_better_epoch_is
self.model,
self.optimizer,
self.data_loader,
self.instances,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="+loss",
num_epochs=1,
serialization_dir=self.TEST_DIR,
Expand All @@ -714,7 +713,7 @@ def test_restored_training_returns_best_epoch_metrics_even_if_no_better_epoch_is
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
validation_metric="+loss",
num_epochs=2,
serialization_dir=self.TEST_DIR,
Expand All @@ -736,7 +735,7 @@ def test_restoring_works_with_older_checkpointing(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=3,
serialization_dir=self.TEST_DIR,
)
Expand Down Expand Up @@ -767,7 +766,7 @@ def test_trainer_can_run_gradient_accumulation(self):
self.model,
self.optimizer,
self.data_loader,
validation_dataset_loader=self.validation_data_loader,
validation_data_loader=self.validation_data_loader,
num_epochs=2,
num_gradient_accumulation_steps=steps_to_accumulate,
)
Expand Down