Skip to content
This repository was archived by the owner on Nov 17, 2023. It is now read-only.

Commit cab1dfa

Browse files
authored
Upgrade archive utility and add back FC improvement (#15171)
* Upgrade archive utility and add back FC improvement This reverts commit 6543488. * Change permissions for Ubuntu AR * Extract and cd into binutils dir * Allow AR path to be chosen by user * Add AR path to build * Fix AR paths * Revert AR flag in makefile * Build from source doc updated * Add comment * Add warning for smaller ar versions, add set -ex
1 parent 85aaa3a commit cab1dfa

7 files changed

Lines changed: 98 additions & 3 deletions

File tree

Makefile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,32 @@ endif
368368

369369
# Guard against displaying nvcc info messages to users not using CUDA.
370370
ifeq ($(USE_CUDA), 1)
371+
# Get AR version, compare with expected ar version and find bigger and smaller version of the two
372+
AR_VERSION := $(shell ar --version | egrep -o "([0-9]{1,}\.)+[0-9]{1,}")
373+
EXPECTED_AR_VERSION := $(shell echo "2.27")
374+
LARGE_VERSION := $(shell printf '%s\n' "$(AR_VERSION)" "$(EXPECTED_AR_VERSION)" | sort -V | tail -n 1)
375+
SMALL_VERSION := $(shell printf '%s\n' "$(AR_VERSION)" "$(EXPECTED_AR_VERSION)" | sort -V | head -n 1)
376+
371377
# If NVCC is not at the location specified, use CUDA_PATH instead.
372378
ifeq ("$(wildcard $(NVCC))","")
373379
ifneq ($(USE_CUDA_PATH), NONE)
374380
NVCC=$(USE_CUDA_PATH)/bin/nvcc
381+
382+
# if larger version is the expected one and larger != smaller
383+
# this means ar version is less than expected version and user needs to be warned
384+
ifeq ($(LARGE_VERSION), $(EXPECTED_AR_VERSION))
385+
ifneq ($(LARGE_VERSION), $(SMALL_VERSION))
386+
define n
387+
388+
389+
endef
390+
391+
$(warning WARNING: Archive utility: ar version being used is less than 2.27.0. $n \
392+
Note that with USE_CUDA=1 flag and USE_CUDNN=1 this is known to cause problems. $n \
393+
For more info see: https://github.com/apache/incubator-mxnet/issues/15084)
394+
$(shell sleep 5)
395+
endif
396+
endif
375397
$(info INFO: nvcc was not found on your path)
376398
$(info INFO: Using $(NVCC) as nvcc path)
377399
else

ci/docker/Dockerfile.build.ubuntu_build_cuda

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ COPY install/ubuntu_clang.sh /work/
4343
RUN /work/ubuntu_clang.sh
4444
COPY install/ubuntu_mklml.sh /work/
4545
RUN /work/ubuntu_mklml.sh
46+
COPY install/ubuntu_ar.sh /work/
47+
RUN /work/ubuntu_ar.sh
4648

4749
ENV CUDNN_VERSION=7.6.0.64
4850
COPY install/ubuntu_cudnn.sh /work/

ci/docker/install/ubuntu_ar.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
# under the License.
19+
20+
# build and install are separated so changes to build don't invalidate
21+
# the whole docker cache for the image
22+
23+
set -ex
24+
25+
wget https://mirror.clarkson.edu/gnu/binutils/binutils-2.27.tar.gz
26+
27+
export DEBIAN_FRONTEND=noninteractive
28+
apt-get update || true
29+
apt-get install -y \
30+
wget
31+
32+
mkdir /opt/binutils_install && mkdir /opt/binutils_install && mkdir /opt/binutils && cd /opt/binutils
33+
wget -nv https://mirror.clarkson.edu/gnu/binutils/binutils-2.27.tar.gz
34+
tar -xvf binutils-2.27.tar.gz && cd binutils-2.27
35+
./configure --prefix=/opt/binutils_other --exec-prefix=/opt/binutils_install
36+
make -j$(nproc)
37+
make install
38+
ln -s /opt/binutils_install/bin/ar /usr/local/bin/ar

docs/install/build_from_source.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ More information on turning these features on or off are found in the following
179179
There is a configuration file for make,
180180
[`make/config.mk`](https://github.com/apache/incubator-mxnet/blob/master/make/config.mk), that contains all the compilation options. You can edit it and then run `make` or `cmake`. `cmake` is recommended for building MXNet (and is required to build with MKLDNN), however you may use `make` instead. For building with Java/Scala/Clojure, only `make` is supported.
181181

182+
**NOTE:** When certain set of build flags are set, MXNet archive increases to more than 4 GB. Since MXNet uses archive internally archive runs into a bug ("File Truncated": [bugreport](https://sourceware.org/bugzilla/show_bug.cgi?id=14625)) for archives greater than 4 GB. Please use ar version 2.27 or greater to overcome this bug. Please see https://github.com/apache/incubator-mxnet/issues/15084 for more details.
183+
182184
<hr>
183185

184186
## Build MXNet

src/operator/nn/fully_connected-inl.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "../elemwise_op_common.h"
3737
#include "../linalg.h"
3838
#include "../../common/utils.h"
39+
#include "../tensor/broadcast_reduce_op.h"
3940

4041
namespace mxnet {
4142
namespace op {
@@ -169,7 +170,18 @@ void FCBackward(const OpContext &ctx, const FullyConnectedParam &param,
169170
// gradient of bias
170171
if (!param.no_bias) {
171172
Tensor<xpu, 1, DType> gbias = in_grad[fullc::kBias].get<xpu, 1, DType>(s);
172-
Assign(gbias, req[fullc::kBias], sum_rows(grad));
173+
TBlob grad_blob = TBlob(grad);
174+
TBlob gbias_blob = TBlob(gbias);
175+
mxnet::TShape x(1, 0);
176+
mxnet::TShape small;
177+
if (shape_assign(&gbias_blob.shape_, Shape2(param.num_hidden, 1))) {
178+
small = gbias_blob.shape_;
179+
} else {
180+
small = ReduceAxesShapeImpl(grad_blob.shape_, dmlc::optional<mxnet::TShape>(x), true, false);
181+
}
182+
ReduceAxesComputeImpl<xpu, mshadow::red::sum, false, false,
183+
mshadow_op::identity>(ctx, {grad_blob}, {req[fullc::kBias]},
184+
{in_grad[fullc::kBias]}, small);
173185
}
174186
// gradient of data
175187
// Legacy approach shown here for comparison:

src/operator/nn/fully_connected.cc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,9 @@ NNVM_REGISTER_OP(_backward_FullyConnected)
316316
const FullyConnectedParam& params = nnvm::get<FullyConnectedParam>(attrs.parsed);
317317
return params.no_bias ? 2 : 3;
318318
})
319-
#if MXNET_USE_MKLDNN == 1
320319
.set_attr<FResourceRequest>("FResourceRequest", [](const NodeAttrs& n) {
321320
return std::vector<ResourceRequest>{ResourceRequest::kTempSpace};
322321
})
323-
#endif
324322
.set_attr<nnvm::TIsBackward>("TIsBackward", true)
325323
.set_attr<nnvm::FInplaceOption>("FInplaceOption", [](const NodeAttrs& attrs){
326324
return std::vector<std::pair<int, int> >{{1, 0}};

tests/python/unittest/test_operator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,27 @@ def test_symbol_pow():
696696
check_symbolic_backward(test, [data_tmp, exp_tmp], [np.ones(shape)], [data_dir, exp_dir])
697697

698698

699+
@with_seed()
700+
def test_fully_connected():
701+
data = mx.sym.var("data")
702+
fc_weight = mx.sym.var("weight")
703+
fc_bias = mx.sym.var("bias")
704+
fc = mx.sym.FullyConnected(data=data, weight=fc_weight, bias=fc_bias, num_hidden=10, no_bias=False, name='fc')
705+
data = mx.nd.random.uniform(shape=(5, 5, 5, 13), dtype=np.float32)
706+
fc_weight = mx.nd.random.uniform(shape=(10, 325), dtype=np.float32)
707+
fc_bias = mx.nd.random.uniform(shape=(10), dtype=np.float32)
708+
fc_bias2 = mx.nd.random.uniform(shape=(10, 1), dtype=np.float32)
709+
data_np = data.asnumpy().reshape(5, 325)
710+
fc_weight_np = np.transpose(fc_weight.asnumpy())
711+
fc_bias_np = fc_bias.asnumpy()
712+
res = np.dot(data_np, fc_weight_np) + fc_bias.asnumpy()
713+
check_symbolic_forward(fc, {'data': data_np, 'weight': fc_weight.asnumpy(), 'bias': fc_bias_np}, {'fc_output': res})
714+
check_numeric_gradient(fc, {'data': data_np, 'weight': fc_weight.asnumpy(), 'bias': fc_bias_np},
715+
numeric_eps=1e-2, rtol=1e-4, atol=1e-2)
716+
# TODO: Fix Bug #15032 when bias has ndim > 1
717+
#check_symbolic_forward(fc, {'data': data_np, 'weight': fc_weight.asnumpy(), 'bias': fc_bias2.asnumpy()}, {'fc_output': res})
718+
719+
699720
@with_seed()
700721
def test_pow_fn():
701722
shape = (3, 4)

0 commit comments

Comments
 (0)