Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Worker globals #449

Merged
merged 10 commits into from Jan 22, 2021
Merged

Worker globals #449

merged 10 commits into from Jan 22, 2021

Conversation

dfalbel
Copy link
Member

@dfalbel dfalbel commented Jan 22, 2021

This PR introduces 2 new parameters to the dataloader function:

  • worker_globals: objects that should be copied to the global environment of each worker.
  • worker_packages: names of packages that should be loaded with library into each worker.

The code wouldn't work before, because the hello_fn wouldn't be available in the workers:

ds <- dataset(
    .length = function() {20},
    initialize = function() {},
    .getitem = function(id) {
      hello_fn()
    }
  )
  
dl <- dataloader(ds(), batch_size = 10, num_workers = 2)

You can now create the dataloader with:

dl <- dataloader(ds(), batch_size = 10, num_workers = 2, worker_globals = list(
    hello_fn = hello_fn
  ))

Fix for #444

cc @Athospd

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant