mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Summary:
This PR adds the functional version of `DataParallel` (i.e. `data_parallel`) to the C++ frontend.
For this, I had to:
1. Add "differentiable" versions of scatter and gather, which perform their inverse operation in the backward pass, to C++. I've added them under `torch/csrc/autograd/functions/comm.{h,cpp}`. I had to move some utilities from `VariableType.cpp` into `torch/csrc/autograd/functions/utils.h`, and changed them a bit to fix the `const_cast`s for which there were `TODO`s,
2. Implement the `replicate`, `parallel_apply` and the combining `data_parallel` functions in C++.
`replicate` is implemented based on our existing `clone()` interface, along with the ability to set the current device via `at::OptionsGuard` (so nice).
`parallel_apply` is implemented using `at::parallel_for` (CC cpuhrsch) and [follows the code from PyTorch](https://github.com/pytorch/pytorch/blob/master/torch/nn/parallel/parallel_apply.py).
Added lots of tests for these things.
apaszke ezyang ebetica colesbury
Pull Request resolved: https://github.com/pytorch/pytorch/pull/9234
Differential Revision: D8865182
Pulled By: goldsborough
fbshipit-source-id: 4f1fecf2b3f3bc1540c071dfb2d23dd45de433e4
33 lines
963 B
C++
33 lines
963 B
C++
#define CATCH_CONFIG_RUNNER
|
|
#include <catch.hpp>
|
|
|
|
#include <torch/cuda.h>
|
|
|
|
#include <iostream>
|
|
|
|
// Custom main to disable CUDA tests when they are not available.
|
|
// https://github.com/catchorg/Catch2/blob/master/docs/own-main.md
|
|
|
|
int main(int argc, char* argv[]) {
|
|
Catch::Session session;
|
|
|
|
const auto return_code = session.applyCommandLine(argc, argv);
|
|
if (return_code != 0) {
|
|
return return_code;
|
|
}
|
|
|
|
// ~ disables tags.
|
|
if (!torch::cuda::is_available()) {
|
|
std::cerr << "CUDA not available. Disabling [cuda] and [multi-cuda] tests"
|
|
<< std::endl;
|
|
session.configData().testsOrTags.emplace_back("~[cuda]");
|
|
session.configData().testsOrTags.emplace_back("~[multi-cuda]");
|
|
} else if (torch::cuda::device_count() < 2) {
|
|
std::cerr << "Only one CUDA device detected. Disabling [multi-cuda] tests"
|
|
<< std::endl;
|
|
session.configData().testsOrTags.emplace_back("~[multi-cuda]");
|
|
}
|
|
|
|
return session.run();
|
|
}
|