Skip to content

Commit

Permalink
Update on "[ONNX] Fix bug in unfold symbolic (#50504)"
Browse files Browse the repository at this point in the history
Fix bug in unfold symbolic

[ghstack-poisoned]
  • Loading branch information
BowenBao committed Feb 2, 2021
2 parents 5ab9320 + c95cc58 commit 525e28a
Show file tree
Hide file tree
Showing 119 changed files with 1,770 additions and 630 deletions.
43 changes: 25 additions & 18 deletions .circleci/docker/common/install_rocm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@

set -ex

install_magma() {
# "install" hipMAGMA into /opt/rocm/magma by copying after build
git clone https://bitbucket.org/icl/magma.git -b hipMAGMA
pushd magma
cp make.inc-examples/make.inc.hip-mkl-gcc make.inc
echo 'LIBDIR += -L$(MKLROOT)/lib' >> make.inc
echo 'LIB += -Wl,--enable-new-dtags -Wl,--rpath,/opt/rocm/lib -Wl,--rpath,$(MKLROOT)/lib -Wl,--rpath,/opt/rocm/magma/lib' >> make.inc
echo 'DEVCCFLAGS += --amdgpu-target=gfx803 --amdgpu-target=gfx900 --amdgpu-target=gfx906 --amdgpu-target=gfx908' >> make.inc
export PATH="${PATH}:/opt/rocm/bin"
make -f make.gen.hipMAGMA -j $(nproc)
make lib/libmagma.so -j $(nproc) MKLROOT=/opt/conda
make testing/testing_dgemm -j $(nproc) MKLROOT=/opt/conda
popd
mv magma /opt/rocm
}

install_ubuntu() {
apt-get update
if [[ $UBUNTU_VERSION == 18.04 ]]; then
Expand All @@ -10,7 +26,6 @@ install_ubuntu() {
fi
apt-get install -y kmod
apt-get install -y wget
apt-get install -y libopenblas-dev

# Need the libc++1 and libc++abi1 libraries to allow torch._C to load at runtime
apt-get install -y libc++1
Expand All @@ -24,13 +39,7 @@ install_ubuntu() {
DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated \
rocm-dev \
rocm-utils \
rocfft \
miopen-hip \
rocblas \
hipsparse \
rocrand \
hipcub \
rocthrust \
rocm-libs \
rccl \
rocprofiler-dev \
roctracer-dev
Expand All @@ -44,9 +53,11 @@ install_ubuntu() {
DEBIAN_FRONTEND=noninteractive apt-get install -y --allow-unauthenticated ${MIOPENKERNELS}
fi

# Cleanup
apt-get autoclean && apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
install_magma

# Cleanup
apt-get autoclean && apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
}

install_centos() {
Expand All @@ -70,17 +81,13 @@ install_centos() {
yum install -y \
rocm-dev \
rocm-utils \
rocfft \
miopen-hip \
rocblas \
hipsparse \
rocrand \
rocm-libs \
rccl \
hipcub \
rocthrust \
rocprofiler-dev \
roctracer-dev

install_magma

# Cleanup
yum clean all
rm -rf /var/cache/yum
Expand Down
1 change: 1 addition & 0 deletions .circleci/docker/ubuntu-rocm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ ENV PATH /opt/rocm/hcc/bin:$PATH
ENV PATH /opt/rocm/hip/bin:$PATH
ENV PATH /opt/rocm/opencl/bin:$PATH
ENV PATH /opt/rocm/llvm/bin:$PATH
ENV MAGMA_HOME /opt/rocm/magma
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8

Expand Down
5 changes: 5 additions & 0 deletions .jenkins/pytorch/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ if [[ "$BUILD_ENVIRONMENT" == *coverage* ]]; then
export USE_CPP_CODE_COVERAGE=ON
fi

if [[ "$BUILD_ENVIRONMENT" == *cuda11* ]]; then
# enable split torch_cuda build option in CMake
export BUILD_SPLIT_CUDA=ON
fi

# TODO: Don't run this...
pip_install -r requirements.txt || true

Expand Down
4 changes: 4 additions & 0 deletions .jenkins/pytorch/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ if [[ "$BUILD_ENVIRONMENT" == *coverage* ]]; then
export PYTORCH_COLLECT_COVERAGE=1
fi

if [[ "$BUILD_ENVIRONMENT" == *cuda11.1* ]]; then
export BUILD_SPLIT_CUDA=ON
fi

if [[ "$BUILD_ENVIRONMENT" == *rocm* ]]; then
# Print GPU info
rocminfo | grep -E 'Name:.*\sgfx|Marketing'
Expand Down
5 changes: 4 additions & 1 deletion .jenkins/pytorch/win-test-helpers/build_pytorch.bat
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ if "%REBUILD%" == "" (
aws s3 cp "s3://ossci-windows/Restore PyTorch Environment.lnk" "C:\Users\circleci\Desktop\Restore PyTorch Environment.lnk"
)
)
:: tests if BUILD_ENVIRONMENT contains cuda11 as a substring
if not x%BUILD_ENVIRONMENT:cuda11=%==x%BUILD_ENVIRONMENT% (
set BUILD_SPLIT_CUDA=ON
)

python setup.py install --cmake && sccache --show-stats && (
if "%BUILD_ENVIRONMENT%"=="" (
Expand All @@ -118,4 +122,3 @@ python setup.py install --cmake && sccache --show-stats && (
7z a %TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\torch %CONDA_PARENT_DIR%\Miniconda3\Lib\site-packages\caffe2 && copy /Y "%TMP_DIR_WIN%\%IMAGE_COMMIT_TAG%.7z" "%PYTORCH_FINAL_PACKAGE_DIR%\"
)
)

4 changes: 4 additions & 0 deletions .jenkins/pytorch/win-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ if [ -n "$CIRCLE_PULL_REQUEST" ]; then
file_diff_from_base "$DETERMINE_FROM"
fi

if [[ "${CIRCLE_JOB}" == *11.1* ]]; then
export BUILD_SPLIT_CUDA=ON
fi

run_tests() {
if [ -z "${JOB_BASE_NAME}" ] || [[ "${JOB_BASE_NAME}" == *-test ]]; then
$SCRIPT_HELPERS_DIR/test_python_nn.bat "$DETERMINE_FROM"
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@ option(COLORIZE_OUTPUT "Colorize output during compilation" ON)
option(USE_ASAN "Use Address Sanitizer" OFF)
option(USE_TSAN "Use Thread Sanitizer" OFF)
option(USE_CUDA "Use CUDA" ON)
# BUILD_SPLIT_CUDA must also be exported as an environment variable before building, with
# `export BUILD_SPLIT_CUDA=1` because cpp_extension.py can only work properly if this variable
# also exists in the environment.
# This option is incompatible with CUDA_SEPARABLE_COMPILATION.
cmake_dependent_option(
BUILD_SPLIT_CUDA "Split torch_cuda library into torch_cuda_cu and torch_cuda_cpp" OFF
"USE_CUDA AND NOT CUDA_SEPARABLE_COMPILATION" OFF)
option(USE_FAST_NVCC "Use parallel NVCC build" OFF)
option(USE_ROCM "Use ROCm" ON)
option(CAFFE2_STATIC_LINK_CUDA "Statically link CUDA libraries" OFF)
Expand Down
18 changes: 12 additions & 6 deletions aten/src/ATen/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,20 @@ if(USE_CUDA AND NOT USE_ROCM)
if(CAFFE2_USE_CUDNN)
list(APPEND ATen_CUDA_DEPENDENCY_LIBS ${CUDNN_LIBRARIES})
endif()
if($ENV{ATEN_STATIC_CUDA})
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libculibos.a")
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart_static.a")
endif($ENV{ATEN_STATIC_CUDA})
endif()


if(USE_MAGMA)
list(APPEND ATen_CUDA_DEPENDENCY_LIBS ${MAGMA_LIBRARIES})
if(USE_CUDA)
list(APPEND ATen_CUDA_DEPENDENCY_LIBS ${MAGMA_LIBRARIES})
endif(USE_CUDA)
if(USE_ROCM)
list(APPEND ATen_HIP_DEPENDENCY_LIBS ${MAGMA_LIBRARIES})
endif(USE_ROCM)
if(MSVC)
if($ENV{TH_BINARY_BUILD})
# Do not do this on Linux: see Note [Extra MKL symbols for MAGMA in torch_cpu]
Expand All @@ -351,11 +362,6 @@ if(USE_CUDA AND NOT USE_ROCM)
endif($ENV{TH_BINARY_BUILD})
endif(MSVC)
endif(USE_MAGMA)
if($ENV{ATEN_STATIC_CUDA})
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libculibos.a")
list(APPEND ATen_CUDA_DEPENDENCY_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib64/libcudart_static.a")
endif($ENV{ATEN_STATIC_CUDA})
endif()

# NB: We're relying on cmake/Dependencies.cmake to appropriately setup HIP dependencies.
# In principle we could duplicate them, but handling the rocblas
Expand Down
1 change: 1 addition & 0 deletions aten/src/ATen/core/Dict.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ using valid_dict_key_types = guts::typelist::typelist<
int64_t,
std::string,
double,
c10::complex<double>,
bool,
at::Tensor
>;
Expand Down
3 changes: 3 additions & 0 deletions aten/src/ATen/core/Dict_inl.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <ATen/core/ivalue.h>
#include <c10/util/hash.h>

namespace c10 {
namespace detail {
Expand Down Expand Up @@ -43,6 +44,8 @@ inline size_t DictKeyHash::operator()(const IValue& ivalue) const {
return std::hash<std::string>()(ivalue.toStringRef());
} else if (ivalue.isDouble()) {
return std::hash<double>()(ivalue.toDouble());
} else if (ivalue.isComplexDouble()) {
return c10::hash<c10::complex<double>>()(ivalue.toComplexDouble());
} else if (ivalue.isBool()) {
return std::hash<bool>()(ivalue.toBool());
} else if (ivalue.isTensor()) {
Expand Down
43 changes: 25 additions & 18 deletions aten/src/ATen/core/function_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,16 @@ struct Argument {
}

Argument cloneWithType(TypePtr new_type) const {
return Argument(name_, new_type, N_, default_value_, kwarg_only_, alias_info_);
return Argument(
name_,
std::move(new_type),
N_,
default_value_,
kwarg_only_,
alias_info_);
}

// this function check whether this Argument is backward compatible with
// this function checks whether this Argument is backward compatible with
// the old one. we consider the following cases are backward compatible:
// 1) two arguments are equal
// 2) this arg's type should be subtype of old
Expand All @@ -97,7 +103,7 @@ struct Argument {
const Argument& old,
std::ostream* why_not=nullptr) const;

private:
private:
std::string name_;
TypePtr type_;
// for list types, an optional statically known length for the list
Expand Down Expand Up @@ -223,7 +229,7 @@ struct FunctionSchema {
}
}

public:
public:

void dump() const;

Expand Down Expand Up @@ -265,13 +271,13 @@ struct FunctionSchema {
}
FunctionSchema cloneWithName(std::string name, std::string overload_name) const {
return FunctionSchema(
std::move(name),
std::move(overload_name),
arguments(),
returns(),
is_vararg(),
is_varret()
);
std::move(name),
std::move(overload_name),
arguments(),
returns(),
is_vararg(),
is_varret()
);
}
FunctionSchema cloneWithArguments(std::vector<Argument> new_arguments) const {
return FunctionSchema(
Expand Down Expand Up @@ -305,7 +311,8 @@ struct FunctionSchema {
// values.
void checkAndNormalizeInputs(
std::vector<IValue>& inputs,
const std::unordered_map<std::string, IValue>& kwargs) const;
const std::unordered_map<std::string, IValue>& kwargs =
std::unordered_map<std::string, IValue>{}) const;

std::string findErrorInKwargs(const std::vector<std::string>& kwargs) const;

Expand Down Expand Up @@ -354,11 +361,11 @@ struct FunctionSchema {

inline bool operator==(const FunctionSchema& lhs, const FunctionSchema& rhs) {
return lhs.name() == rhs.name()
&& lhs.overload_name() == rhs.overload_name()
&& lhs.arguments() == rhs.arguments()
&& lhs.returns() == rhs.returns()
&& lhs.is_vararg() == rhs.is_vararg()
&& lhs.is_varret() == rhs.is_varret();
&& lhs.overload_name() == rhs.overload_name()
&& lhs.arguments() == rhs.arguments()
&& lhs.returns() == rhs.returns()
&& lhs.is_vararg() == rhs.is_vararg()
&& lhs.is_varret() == rhs.is_varret();
}

inline bool operator!=(const FunctionSchema& lhs, const FunctionSchema& rhs) {
Expand All @@ -375,7 +382,7 @@ inline std::ostream& operator<<(std::ostream& out, const Argument& arg) {
// so we always use Type(alias)? format
auto type = arg.type();
bool is_opt = type->kind() == OptionalType::Kind;
auto unopt_type = is_opt ? type->cast<OptionalType>()->getElementType() : type;
auto unopt_type = is_opt ? type->castRaw<OptionalType>()->getElementType() : type;

if (unopt_type->kind() == ListType::Kind && arg.N()) {
// sized lists get size N from arg, not type
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/ivalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ std::ostream& printMaybeAnnotatedDict(
std::ostream& out,
const IValue& the_dict,
IValueFormatter formatter) {
auto value_type = the_dict.type()->cast<DictType>()->getValueType();
auto value_type = the_dict.type()->castRaw<DictType>()->getValueType();
if (the_dict.toGenericDict().size() == 0 ||
!elementTypeCanBeInferredFromMembers(value_type)) {
out << "annotate(" << the_dict.type()->annotation_str() << ",";
Expand Down
5 changes: 3 additions & 2 deletions aten/src/ATen/core/jit_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,14 +738,15 @@ struct TORCH_API DictType : public Type {
case TypeKind::IntType:
case TypeKind::BoolType:
case TypeKind::FloatType:
case TypeKind::ComplexDoubleType:
case TypeKind::StringType:
case TypeKind::TensorType:
return DictTypePtr(new DictType(key, value));
default:
AT_ERROR(
"Cannot create dict for key type '",
key->str(),
"', only int, float, Tensor and string keys are supported");
"', only int, float, complex, Tensor and string keys are supported");
}
}

Expand Down Expand Up @@ -974,7 +975,7 @@ struct TORCH_API TupleType : public NamedType {
}

const auto& l_elements = elements();
const auto& r_elements = rhs.cast<TupleType>()->elements();
const auto& r_elements = rhs.castRaw<TupleType>()->elements();
if (l_elements.size() != r_elements.size())
return false;
for (size_t i = 0; i < l_elements.size(); ++i) {
Expand Down
2 changes: 1 addition & 1 deletion aten/src/ATen/core/jit_type_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ struct TORCH_API Type : std::enable_shared_from_this<Type> {
template <typename T>
const T* castRaw() const {
if (T::Kind == kind()) {
return static_cast<T*>(this);
return static_cast<const T*>(this);
}
return nullptr;
}
Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/core/op_registration/infer_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ std::vector<Argument> createArgumentVector(c10::ArrayRef<ArgumentDef> args) {
C10_EXPORT FunctionSchema make_function_schema(std::string&& name, std::string&& overload_name, c10::ArrayRef<ArgumentDef> arguments, c10::ArrayRef<ArgumentDef> returns) {
return FunctionSchema(std::move(name), std::move(overload_name), createArgumentVector(arguments), createArgumentVector(returns));
}

C10_EXPORT FunctionSchema make_function_schema(c10::ArrayRef<ArgumentDef> arguments, c10::ArrayRef<ArgumentDef> returns) {
return make_function_schema("", "", arguments, returns);
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions aten/src/ATen/core/op_registration/infer_schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ struct createSingleReturn {
};

C10_API FunctionSchema make_function_schema(std::string&& name, std::string&& overload_name, c10::ArrayRef<ArgumentDef> arguments, c10::ArrayRef<ArgumentDef> returns);
C10_API FunctionSchema make_function_schema(c10::ArrayRef<ArgumentDef> arguments, c10::ArrayRef<ArgumentDef> returns);

/// Creates a `FunctionSchema` object from a `FunctionTraits` type for a
/// function. Flattens std::tuple returns into multiple return types
template <typename FunctionTraits>
FunctionSchema createFunctionSchemaFromTraitsFlattenedReturns(std::string&& name, std::string&& overload_name) {
FunctionSchema createFunctionSchemaFromTraitsFlattenedReturns() {
using ReturnType = typename FunctionTraits::return_type;
using ParameterTypes = typename FunctionTraits::parameter_types;

Expand All @@ -121,7 +122,7 @@ FunctionSchema createFunctionSchemaFromTraitsFlattenedReturns(std::string&& name
constexpr auto arguments = createArguments<ParameterTypes>::call();
constexpr auto returns = createReturns<ReturnType>::call();

return make_function_schema(std::move(name), std::move(overload_name), arguments, returns);
return make_function_schema(arguments, returns);
}

/// Creates a `FunctionSchema` object from a `FunctionTraits` type for a
Expand All @@ -144,8 +145,8 @@ FunctionSchema createFunctionSchemaFromTraitsSingleReturn(std::string&& name, st
}

template<class FuncType>
FunctionSchema inferFunctionSchemaFlattenedReturns(std::string&& name, std::string&& overload_name) {
return detail::infer_schema::createFunctionSchemaFromTraitsFlattenedReturns<guts::infer_function_traits_t<FuncType>>(std::move(name), std::move(overload_name));
FunctionSchema inferFunctionSchemaFlattenedReturns() {
return detail::infer_schema::createFunctionSchemaFromTraitsFlattenedReturns<guts::infer_function_traits_t<FuncType>>();
}

template<class FuncType>
Expand Down

0 comments on commit 525e28a

Please sign in to comment.