Skip to content

Commit bfebaec

Browse files
authored
Merge pull request #218 from iotamudelta/ifu
Merge from upstream
2 parents 88f25ad + 613dacb commit bfebaec

File tree

408 files changed

+4566
-15076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

408 files changed

+4566
-15076
lines changed

.jenkins/pytorch/macos-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if [ ! -d "${PYTORCH_ENV_DIR}/miniconda3" ]; then
1515
fi
1616
export PATH="${PYTORCH_ENV_DIR}/miniconda3/bin:$PATH"
1717
source ${PYTORCH_ENV_DIR}/miniconda3/bin/activate
18-
conda install -y mkl mkl-include numpy pyyaml setuptools cmake cffi ninja
18+
conda install -y mkl mkl-include numpy pyyaml setuptools cmake cffi ninja future six
1919
if [ -z "${IN_CIRCLECI}" ]; then
2020
rm -rf ${PYTORCH_ENV_DIR}/miniconda3/lib/python3.6/site-packages/torch*
2121
fi

.jenkins/pytorch/perf_test/compare_with_baseline.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import json
3+
import math
34
import numpy
45
import argparse
56

@@ -35,14 +36,25 @@
3536
print("population mean: ", mean)
3637
print("population sigma: ", sigma)
3738

39+
# Let the test pass if baseline number is NaN (which happened in
40+
# the past when we didn't have logic for catching NaN numbers)
41+
if math.isnan(mean) or math.isnan(sigma):
42+
mean = sys.maxsize
43+
sigma = 0.001
44+
3845
sample_stats_data = json.loads(args.sample_stats)
3946

40-
sample_mean = sample_stats_data['mean']
41-
sample_sigma = sample_stats_data['sigma']
47+
sample_mean = float(sample_stats_data['mean'])
48+
sample_sigma = float(sample_stats_data['sigma'])
4249

4350
print("sample mean: ", sample_mean)
4451
print("sample sigma: ", sample_sigma)
4552

53+
if math.isnan(sample_mean):
54+
raise Exception('''Error: sample mean is NaN''')
55+
elif math.isnan(sample_sigma):
56+
raise Exception('''Error: sample sigma is NaN''')
57+
4658
z_value = (sample_mean - mean) / sigma
4759

4860
print("z-value: ", z_value)

.jenkins/pytorch/perf_test/test_gpu_speed_mnist.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ test_gpu_speed_mnist () {
2020
SAMPLE_ARRAY=()
2121
NUM_RUNS=$1
2222

23+
# Needs warm up to get accurate number
24+
python main.py --epochs 1 --no-log
25+
2326
for (( i=1; i<=$NUM_RUNS; i++ )) do
2427
runtime=$(get_runtime_of_command python main.py --epochs 1 --no-log)
2528
echo $runtime

.jenkins/pytorch/win-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ curl https://repo.continuum.io/miniconda/Miniconda3-latest-Windows-x86_64.exe -O
4545
call C:\\Jenkins\\Miniconda3\\Scripts\\activate.bat C:\\Jenkins\\Miniconda3
4646
call conda install -y -q numpy mkl cffi pyyaml boto3
4747
48-
pip install ninja
48+
pip install ninja future
4949
5050
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x86_amd64
5151

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ You can then build the documentation by running ``make <format>`` from the
239239
### Previous Versions
240240

241241
Installation instructions and binaries for previous PyTorch versions may be found
242-
on [our website](http://pytorch.org/previous-versions/).
242+
on [our website](http://pytorch.org/previous-versions).
243243

244244

245245
## Getting Started

aten/src/ATen/CPUApplyUtils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ inline std::string _all_equal_numel_error(at::ArrayRef<Tensor> tensors) {
207207
for (size_t i = 0; i < tensors.size() - 1; i++) {
208208
oss << tensors[i].sizes() << ", ";
209209
}
210-
oss << "and " << tensors[tensors.size() - 1]
210+
oss << "and " << tensors[tensors.size() - 1].sizes()
211211
<< " to have the same number of elements, but got ";
212212
for (size_t i = 0; i < tensors.size() - 1; i++) {
213213
oss << tensors[i].numel() << ", ";
@@ -220,7 +220,7 @@ inline std::string _all_equal_numel_error(at::ArrayRef<Tensor> tensors) {
220220
inline bool _apply_preamble(ArrayRef<Tensor> tensors) {
221221
checkBackend("CPU_tensor_apply", tensors, Backend::CPU);
222222
if (!_all_equal_numel(tensors))
223-
throw std::runtime_error(_all_equal_numel_error(tensors));
223+
AT_ERROR(_all_equal_numel_error(tensors));
224224
// An empty tensor has no elements
225225
for (auto& t : tensors)
226226
if (t.numel() == 0)

aten/src/ATen/Declarations.cwrap

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,38 +3218,6 @@
32183218
kwarg_only: True
32193219
- double p
32203220
]]
3221-
[[
3222-
name: _bernoulli_
3223-
backends:
3224-
- CPU
3225-
- CUDA
3226-
cname: bernoulli
3227-
return: self
3228-
variants: function
3229-
arguments:
3230-
- THTensor* self
3231-
- arg: THGenerator* generator
3232-
default: nullptr
3233-
kwarg_only: True
3234-
- double p
3235-
]]
3236-
[[
3237-
name: _th_bernoulli
3238-
types:
3239-
- Float
3240-
- Double
3241-
return: argument 0
3242-
variants: function
3243-
cname: bernoulli_Tensor
3244-
arguments:
3245-
- arg: THTensor* output
3246-
output: True
3247-
resize: self
3248-
- arg: THGenerator* generator
3249-
default: nullptr
3250-
kwarg_only: True
3251-
- THTensor* self
3252-
]]
32533221
[[
32543222
name: _dirichlet_grad
32553223
types:

aten/src/ATen/core/DeviceType.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <ATen/core/Macros.h>
99

1010
#include <ostream>
11+
#include <functional>
1112

1213
namespace at {
1314

@@ -32,3 +33,11 @@ AT_CORE_API std::string DeviceTypeName(
3233
AT_CORE_API std::ostream& operator<<(std::ostream& stream, at::DeviceType type);
3334

3435
} // namespace at
36+
37+
namespace std {
38+
template <> struct hash<at::DeviceType> {
39+
std::size_t operator()(const at::DeviceType &k) const {
40+
return std::hash<int>()(static_cast<int>(k));
41+
}
42+
};
43+
} // namespace std

aten/src/ATen/core/Tensor.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,12 +441,10 @@ struct AT_API Tensor {
441441
Tensor & atan_();
442442
Tensor baddbmm(const Tensor & batch1, const Tensor & batch2, Scalar beta=1, Scalar alpha=1) const;
443443
Tensor & baddbmm_(const Tensor & batch1, const Tensor & batch2, Scalar beta=1, Scalar alpha=1);
444-
Tensor bernoulli(const Tensor & p, Generator * generator=nullptr) const;
445-
Tensor bernoulli(double p, Generator * generator=nullptr) const;
446-
Tensor bernoulli() const;
444+
Tensor bernoulli(Generator * generator=nullptr) const;
447445
Tensor & bernoulli_(const Tensor & p, Generator * generator=nullptr);
448-
Tensor & bernoulli_(double p, Generator * generator=nullptr);
449-
Tensor & bernoulli_();
446+
Tensor & bernoulli_(double p=0.5, Generator * generator=nullptr);
447+
Tensor bernoulli(double p, Generator * generator=nullptr) const;
450448
Tensor bincount(const Tensor & weights={}, int64_t minlength=0) const;
451449
Tensor bmm(const Tensor & mat2) const;
452450
Tensor ceil() const;

aten/src/ATen/core/TensorMethods.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,23 +605,17 @@ inline Tensor Tensor::baddbmm(const Tensor & batch1, const Tensor & batch2, Scal
605605
inline Tensor & Tensor::baddbmm_(const Tensor & batch1, const Tensor & batch2, Scalar beta, Scalar alpha) {
606606
return type().baddbmm_(*this, batch1, batch2, beta, alpha);
607607
}
608-
inline Tensor Tensor::bernoulli(const Tensor & p, Generator * generator) const {
609-
return type().bernoulli(*this, p, generator);
610-
}
611-
inline Tensor Tensor::bernoulli(double p, Generator * generator) const {
612-
return type().bernoulli(*this, p, generator);
613-
}
614-
inline Tensor Tensor::bernoulli() const {
615-
return type().bernoulli(*this);
608+
inline Tensor Tensor::bernoulli(Generator * generator) const {
609+
return type().bernoulli(*this, generator);
616610
}
617611
inline Tensor & Tensor::bernoulli_(const Tensor & p, Generator * generator) {
618612
return type().bernoulli_(*this, p, generator);
619613
}
620614
inline Tensor & Tensor::bernoulli_(double p, Generator * generator) {
621615
return type().bernoulli_(*this, p, generator);
622616
}
623-
inline Tensor & Tensor::bernoulli_() {
624-
return type().bernoulli_(*this);
617+
inline Tensor Tensor::bernoulli(double p, Generator * generator) const {
618+
return type().bernoulli(*this, p, generator);
625619
}
626620
inline Tensor Tensor::bincount(const Tensor & weights, int64_t minlength) const {
627621
return type().bincount(*this, weights, minlength);

aten/src/ATen/core/Type.h

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,6 @@ struct AT_API Type {
381381
virtual Tensor all(const Tensor & self, int64_t dim, bool keepdim) const = 0;
382382
virtual bool allclose(const Tensor & self, const Tensor & other, double rtol, double atol, bool equal_nan) const = 0;
383383
virtual Tensor any(const Tensor & self, int64_t dim, bool keepdim) const = 0;
384-
AT_DEPRECATED(virtual Tensor arange(Scalar start, Scalar end, Scalar step) const = 0);
385-
AT_DEPRECATED(virtual Tensor arange(Scalar end) const = 0);
386384
virtual Tensor argmax(const Tensor & self, int64_t dim, bool keepdim) const = 0;
387385
virtual Tensor argmax(const Tensor & self) const = 0;
388386
virtual Tensor argmin(const Tensor & self, int64_t dim, bool keepdim) const = 0;
@@ -397,12 +395,10 @@ struct AT_API Type {
397395
virtual Tensor & atan_(Tensor & self) const = 0;
398396
virtual Tensor baddbmm(const Tensor & self, const Tensor & batch1, const Tensor & batch2, Scalar beta, Scalar alpha) const = 0;
399397
virtual Tensor & baddbmm_(Tensor & self, const Tensor & batch1, const Tensor & batch2, Scalar beta, Scalar alpha) const = 0;
400-
virtual Tensor bernoulli(const Tensor & self, const Tensor & p, Generator * generator) const = 0;
401-
virtual Tensor bernoulli(const Tensor & self, double p, Generator * generator) const = 0;
402-
virtual Tensor bernoulli(const Tensor & self) const = 0;
398+
virtual Tensor bernoulli(const Tensor & self, Generator * generator) const = 0;
403399
virtual Tensor & bernoulli_(Tensor & self, const Tensor & p, Generator * generator) const = 0;
404400
virtual Tensor & bernoulli_(Tensor & self, double p, Generator * generator) const = 0;
405-
virtual Tensor & bernoulli_(Tensor & self) const = 0;
401+
virtual Tensor bernoulli(const Tensor & self, double p, Generator * generator) const = 0;
406402
virtual Tensor bincount(const Tensor & self, const Tensor & weights, int64_t minlength) const = 0;
407403
virtual Tensor bmm(const Tensor & self, const Tensor & mat2) const = 0;
408404
virtual Tensor ceil(const Tensor & self) const = 0;
@@ -430,7 +426,6 @@ struct AT_API Type {
430426
virtual Tensor div(const Tensor & self, Scalar other) const = 0;
431427
virtual Tensor & div_(Tensor & self, Scalar other) const = 0;
432428
virtual Tensor dot(const Tensor & self, const Tensor & tensor) const = 0;
433-
AT_DEPRECATED(virtual Tensor empty(IntList size) const = 0);
434429
virtual Tensor erf(const Tensor & self) const = 0;
435430
virtual Tensor & erf_(Tensor & self) const = 0;
436431
virtual Tensor erfc(const Tensor & self) const = 0;
@@ -441,13 +436,11 @@ struct AT_API Type {
441436
virtual Tensor & expm1_(Tensor & self) const = 0;
442437
virtual Tensor expand(const Tensor & self, IntList size, bool implicit) const = 0;
443438
virtual Tensor expand_as(const Tensor & self, const Tensor & other) const = 0;
444-
AT_DEPRECATED(virtual Tensor eye(int64_t n, int64_t m) const = 0);
445439
virtual Tensor flatten(const Tensor & self, int64_t start_dim, int64_t end_dim) const = 0;
446440
virtual Tensor & fill_(Tensor & self, Scalar value) const = 0;
447441
virtual Tensor & fill_(Tensor & self, const Tensor & value) const = 0;
448442
virtual Tensor floor(const Tensor & self) const = 0;
449443
virtual Tensor & floor_(Tensor & self) const = 0;
450-
AT_DEPRECATED(virtual Tensor full(IntList size, Scalar fill_value) const = 0);
451444
virtual Tensor ger(const Tensor & self, const Tensor & vec2) const = 0;
452445
virtual std::tuple<Tensor,Tensor> gesv(const Tensor & self, const Tensor & A) const = 0;
453446
virtual Tensor fft(const Tensor & self, int64_t signal_ndim, bool normalized) const = 0;
@@ -469,7 +462,6 @@ struct AT_API Type {
469462
virtual bool is_signed(const Tensor & self) const = 0;
470463
virtual bool is_sparse(const Tensor & self) const = 0;
471464
virtual std::tuple<Tensor,Tensor> kthvalue(const Tensor & self, int64_t k, int64_t dim, bool keepdim) const = 0;
472-
AT_DEPRECATED(virtual Tensor linspace(Scalar start, Scalar end, int64_t steps) const = 0);
473465
virtual Tensor log(const Tensor & self) const = 0;
474466
virtual Tensor & log_(Tensor & self) const = 0;
475467
virtual Tensor log10(const Tensor & self) const = 0;
@@ -479,7 +471,6 @@ struct AT_API Type {
479471
virtual Tensor log2(const Tensor & self) const = 0;
480472
virtual Tensor & log2_(Tensor & self) const = 0;
481473
virtual Tensor logdet(const Tensor & self) const = 0;
482-
AT_DEPRECATED(virtual Tensor logspace(Scalar start, Scalar end, int64_t steps) const = 0);
483474
virtual Tensor log_softmax(const Tensor & self, int64_t dim) const = 0;
484475
virtual Tensor logsumexp(const Tensor & self, int64_t dim, bool keepdim) const = 0;
485476
virtual Tensor matmul(const Tensor & self, const Tensor & other) const = 0;
@@ -504,16 +495,9 @@ struct AT_API Type {
504495
virtual Tensor mvlgamma(const Tensor & self, int64_t p) const = 0;
505496
virtual Tensor & mvlgamma_(Tensor & self, int64_t p) const = 0;
506497
virtual Tensor narrow(const Tensor & self, int64_t dim, int64_t start, int64_t length) const = 0;
507-
AT_DEPRECATED(virtual Tensor ones(IntList size) const = 0);
508498
virtual Tensor permute(const Tensor & self, IntList dims) const = 0;
509499
virtual Tensor pin_memory(const Tensor & self) const = 0;
510500
virtual Tensor pinverse(const Tensor & self, double rcond) const = 0;
511-
AT_DEPRECATED(virtual Tensor rand(IntList size, Generator * generator) const = 0);
512-
AT_DEPRECATED(virtual Tensor randint(int64_t high, IntList size, Generator * generator) const = 0);
513-
AT_DEPRECATED(virtual Tensor randint(int64_t low, int64_t high, IntList size, Generator * generator) const = 0);
514-
AT_DEPRECATED(virtual Tensor randn(IntList size, Generator * generator) const = 0);
515-
AT_DEPRECATED(virtual Tensor randperm(int64_t n, Generator * generator) const = 0);
516-
AT_DEPRECATED(virtual Tensor range(Scalar start, Scalar end, Scalar step) const = 0);
517501
virtual Tensor repeat(const Tensor & self, IntList repeats) const = 0;
518502
virtual Tensor reshape(const Tensor & self, IntList shape) const = 0;
519503
virtual Tensor reshape_as(const Tensor & self, const Tensor & other) const = 0;
@@ -581,7 +565,6 @@ struct AT_API Type {
581565
virtual Tensor var(const Tensor & self, int64_t dim, bool unbiased, bool keepdim) const = 0;
582566
virtual Tensor view_as(const Tensor & self, const Tensor & other) const = 0;
583567
virtual Tensor where(const Tensor & condition, const Tensor & self, const Tensor & other) const = 0;
584-
AT_DEPRECATED(virtual Tensor zeros(IntList size) const = 0);
585568
virtual Tensor norm(const Tensor & self, Scalar p) const = 0;
586569
virtual Tensor norm(const Tensor & self, Scalar p, int64_t dim, bool keepdim) const = 0;
587570
virtual Tensor clone(const Tensor & self) const = 0;

aten/src/ATen/core/context_base.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <ATen/core/context_base.h>
2+
3+
namespace caffe2 {
4+
5+
// TODO: rename context.h -> context_cpu.h & context_base.h -> context.h
6+
StaticContextMap& GetStaticContexts() {
7+
static StaticContextMap static_contexts;
8+
return static_contexts;
9+
}
10+
11+
void set_static_context(at::DeviceType t, BaseStaticContext* ptr) {
12+
auto& static_contexts = GetStaticContexts();
13+
static_contexts[t] = ptr;
14+
}
15+
16+
BaseStaticContext* get_static_context(at::DeviceType t) {
17+
auto* ptr = GetStaticContexts()[t];
18+
AT_ASSERTM(ptr, "StaticContext for ", t, " is not registered yet.");
19+
return ptr;
20+
}
21+
22+
} // namespace caffe2

aten/src/ATen/core/context_base.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <ATen/core/Error.h>
1111
#include <ATen/core/UniqueVoidPtr.h>
1212
#include <ATen/core/typeid.h>
13+
#include <ATen/core/ATenGeneral.h>
1314

1415
namespace caffe2 {
1516
class Event;
@@ -184,3 +185,27 @@ class AT_CORE_API BaseContext {
184185
};
185186

186187
} // namespace at
188+
189+
namespace caffe2 {
190+
191+
using at::BaseContext;
192+
using at::BaseStaticContext;
193+
194+
using StaticContextMap = std::unordered_map<at::DeviceType, BaseStaticContext*>;
195+
AT_API StaticContextMap& GetStaticContexts();
196+
AT_API void set_static_context(at::DeviceType t, BaseStaticContext* ptr);
197+
AT_API BaseStaticContext* get_static_context(at::DeviceType t);
198+
199+
template <at::DeviceType t>
200+
struct StaticContextFunctionRegisterer {
201+
explicit StaticContextFunctionRegisterer(BaseStaticContext* ptr) {
202+
set_static_context(t, ptr);
203+
}
204+
};
205+
206+
#define REGISTER_STATIC_CONTEXT(t, f) \
207+
namespace { \
208+
static StaticContextFunctionRegisterer<t> g_static_context_##d(f); \
209+
}
210+
211+
} // namespace caffe2

aten/src/ATen/cpu/vec256/vec256_base.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,4 +438,14 @@ interleave2(const Vec256<T>& a, const Vec256<T>& b) {
438438
Vec256<T>::loadu(static_cast<void*>(buffer2)));
439439
}
440440

441+
template <typename src_T, typename dst_T>
442+
void convert(const src_T *src, dst_T *dst, int64_t n) {
443+
#pragma unroll
444+
for (int64_t i = 0; i < n; i++) {
445+
*dst = static_cast<dst_T>(*src);
446+
src++;
447+
dst++;
448+
}
449+
}
450+
441451
}}}

aten/src/ATen/cpu/vec256/vec256_int.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,38 @@ struct Vec256<int32_t> : public Vec256i {
208208
}
209209
};
210210

211+
template <>
212+
void convert(const int32_t *src, float *dst, int64_t n) {
213+
int64_t i;
214+
// int32_t and float have same size
215+
#pragma unroll
216+
for (i = 0; i <= (n - Vec256<int32_t>::size); i += Vec256<int32_t>::size) {
217+
auto input_vec = _mm256_loadu_si256(reinterpret_cast<const __m256i*>(src + i));
218+
auto output_vec = _mm256_cvtepi32_ps(input_vec);
219+
_mm256_storeu_ps(reinterpret_cast<float*>(dst + i), output_vec);
220+
}
221+
#pragma unroll
222+
for (; i < n; i++) {
223+
dst[i] = static_cast<float>(src[i]);
224+
}
225+
}
226+
227+
template <>
228+
void convert(const int32_t *src, double *dst, int64_t n) {
229+
int64_t i;
230+
// int32_t has half the size of double
231+
#pragma unroll
232+
for (i = 0; i <= (n - Vec256<double>::size); i += Vec256<double>::size) {
233+
auto input_128_vec = _mm_loadu_si128(reinterpret_cast<const __m128i*>(src + i));
234+
auto output_vec = _mm256_cvtepi32_pd(input_128_vec);
235+
_mm256_storeu_pd(reinterpret_cast<double*>(dst + i), output_vec);
236+
}
237+
#pragma unroll
238+
for (; i < n; i++) {
239+
dst[i] = static_cast<double>(src[i]);
240+
}
241+
}
242+
211243
template <>
212244
struct Vec256<int16_t> : public Vec256i {
213245
static constexpr int size = 16;

0 commit comments

Comments
 (0)