Struct DataLoaderOptions

Page Contents

Struct Documentation

struct torch::data::DataLoaderOptions

Options to configure a DataLoader.

Public Functions

DataLoaderOptions() = default
DataLoaderOptions(size_t batch_size)
auto batch_size(const size_t &new_batch_size) -> decltype(*this)

The size of each batch to fetch.

auto batch_size(size_t &&new_batch_size) -> decltype(*this)
const size_t &batch_size() const noexcept
size_t &batch_size() noexcept
auto workers(const size_t &new_workers) -> decltype(*this)

The number of worker threads to launch.

If zero, the main thread will synchronously perform the data loading.

auto workers(size_t &&new_workers) -> decltype(*this)
const size_t &workers() const noexcept
size_t &workers() noexcept
auto max_jobs(const optional<size_t> &new_max_jobs) -> decltype(*this)

The maximum number of jobs to enqueue for fetching by worker threads.

Defaults to two times the number of worker threads.

auto max_jobs(optional<size_t> &&new_max_jobs) -> decltype(*this)
const optional<size_t> &max_jobs() const noexcept
optional<size_t> &max_jobs() noexcept
auto timeout(const optional<std::chrono::milliseconds> &new_timeout) -> decltype(*this)

An optional limit on the time to wait for the next batch.

auto timeout(optional<std::chrono::milliseconds> &&new_timeout) -> decltype(*this)
const optional<std::chrono::milliseconds> &timeout() const noexcept
optional<std::chrono::milliseconds> &timeout() noexcept
auto enforce_ordering(const bool &new_enforce_ordering) -> decltype(*this)

Whether to enforce ordering of batches when multiple are loaded asynchronously by worker threads.

Set to false for better performance if you do not care about determinism.

auto enforce_ordering(bool &&new_enforce_ordering) -> decltype(*this)
const bool &enforce_ordering() const noexcept
bool &enforce_ordering() noexcept
auto drop_last(const bool &new_drop_last) -> decltype(*this)

Whether to omit the last batch if it contains less than batch_size examples.

auto drop_last(bool &&new_drop_last) -> decltype(*this)
const bool &drop_last() const noexcept
bool &drop_last() noexcept


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources