3 #include <torch/data/dataloader/base.h> 4 #include <torch/data/worker_exception.h> 6 #include <torch/csrc/utils/memory.h> 8 #include <c10/util/Exception.h> 24 template <
typename Dataset,
typename Sampler>
27 typename Dataset::BatchType,
28 typename Sampler::BatchRequestType> {
32 typename Dataset::BatchType,
33 typename Sampler::BatchRequestType>;
34 using typename super::BatchRequestType;
42 :
super(
std::move(options)), sampler_(
std::move(sampler)) {
43 for (
size_t w = 0; w < this->
options_.workers; ++w) {
53 torch::make_unique<Dataset>(std::move(dataset));
59 void reset()
override {
68 auto indices = sampler_.next(this->
options_.batch_size);
70 (indices->size() < this->
options_.batch_size &&
74 AT_ASSERT(indices->size() > 0);
A dataloader for stateless datasets.
const FullDataLoaderOptions & options() const noexcept
Returns the options with which the DataLoader was configured.
const FullDataLoaderOptions options_
The options the DataLoader was configured with.
Options to configure a DataLoader.
virtual void reset()
Resets the internal state of the DataLoader, optionally pre-fetching new jobs.
std::vector< std::thread > workers_
The worker threads, running the worker_thread() method.
StatelessDataLoader(Dataset dataset, Sampler sampler, DataLoaderOptions options)
Constructs the StatelessDataLoader from a dataset, a sampler and some options.
std::unique_ptr< Dataset > main_thread_dataset_
The dataset for the main thread, only has a value if the number of worker threads was configured as z...
void worker_thread(Dataset &dataset)
The function that worker threads run.