Skip to content

Commit 3bec5ce

Browse files
committed
fbshipit-source-id: a0c34d05c8b4d5e6de3d81a17c77718961e6313b
1 parent a5f49a3 commit 3bec5ce

Some content is hidden

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

76 files changed

+601
-577
lines changed

CMakeLists.txt

+4-28
Original file line numberDiff line numberDiff line change
@@ -73,24 +73,6 @@ elseif (FLASHLIGHT_USE_UNIFIED AND NOT ArrayFire_Unified_FOUND)
7373
message(FATAL_ERROR "ArrayFire Unified not found: cannot build unified backend")
7474
endif()
7575

76-
# TODO(@jacobkahn): remove these when glog is purged
77-
# Find GLog
78-
find_package(GLOG REQUIRED)
79-
if (GLOG_FOUND)
80-
message(STATUS "GLOG found")
81-
else()
82-
message(FATAL_ERROR "GLOG not found")
83-
endif()
84-
85-
# TODO(@jacobkahn): remove these when glog is purged
86-
# Find GFlags
87-
find_package(GFLAGS REQUIRED)
88-
if (GFLAGS_FOUND)
89-
message(STATUS "GFLAGS found")
90-
else()
91-
message(FATAL_ERROR "GFLAGS not found")
92-
endif()
93-
9476
# Find cereal
9577
find_package(cereal REQUIRED)
9678
if (cereal_FOUND)
@@ -169,26 +151,20 @@ set(
169151
Distributed
170152
Meter
171153
NN
172-
Optim
154+
Optim
173155
)
174156

175157
target_link_libraries(
176158
flashlight
177159
PUBLIC # export dependency library and include paths for each module
178160
${FLASHLIGHT_MODULES}
179-
# TODO(@jacobkahn) remove this once glog is purged
180-
${GLOG_LIBRARIES}
181-
${GFLAGS_LIBRARIES}
182161
)
183162

184163
# Internal includes are impl defined as <flashlight...>
185164
target_include_directories(
186165
flashlight
187166
PRIVATE
188167
${CMAKE_SOURCE_DIR}
189-
# TODO(@jacobkahn) remove these once glog is purged
190-
${GLOG_INCLUDE_DIRS}
191-
${GFLAGS_INCLUDE_DIRS}
192168
)
193169

194170
# Link appropriate ArrayFire backend, set global compile time macros
@@ -275,11 +251,11 @@ install(
275251
flashlightTargets
276252
NAMESPACE
277253
flashlight::
278-
DESTINATION
254+
DESTINATION
279255
${FL_INSTALL_CMAKE_DIR}
280256
COMPONENT
281257
cmake)
282-
258+
283259
# Move headers
284260
install(
285261
DIRECTORY
@@ -312,7 +288,7 @@ configure_package_config_file(
312288
PATH_VARS INCLUDE_DIRS CMAKE_DIR
313289
)
314290
install(FILES
315-
${PROJECT_BINARY_DIR}/cmake/install/flashlightConfig.cmake
291+
${PROJECT_BINARY_DIR}/cmake/install/flashlightConfig.cmake
316292
DESTINATION ${FL_INSTALL_CMAKE_DIR}
317293
COMPONENT cmake
318294
)

Dockerfile-CUDA

+3-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Ubuntu 16.04
55
# CUDA 9.2
66
# CuDNN 7-dev
7-
# glog lastest (apt)
87
# boost latest (apt)
98
# arrayfire 3.6.1 (git, CUDA backend)
109
# googletest master (git)
@@ -35,24 +34,21 @@ RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
3534
g++ \
3635
# for Cereal
3736
libboost-all-dev \
38-
# glogs: for flashlight logging
39-
libgoogle-glog-dev \
40-
# for Cereal
4137
gcc-multilib g++-multilib \
4238
# nccl: for flashlight
4339
libnccl2 libnccl-dev && \
4440
# ==================================================================
4541
# arrayfire https://github.com/arrayfire/arrayfire/wiki/
4642
# ------------------------------------------------------------------
47-
cd /tmp && git clone --recursive https://github.com/arrayfire/arrayfire.git && \
43+
cd /tmp && git clone --recursive https://github.com/arrayfire/arrayfire.git && \
4844
cd arrayfire && git checkout b443e14 && \
4945
mkdir build && cd build && \
5046
cmake .. -DCMAKE_BUILD_TYPE=Release -DAF_BUILD_CPU=OFF -DAF_BUILD_OPENCL=OFF -DAF_BUILD_EXAMPLES=OFF && \
5147
make -j8 && \
5248
make install && \
5349
# ==================================================================
5450
# GoogleTest https://github.com/google/googletest/
55-
# ------------------------------------------------------------------
51+
# ------------------------------------------------------------------
5652
cd /tmp && git clone --recursive https://github.com/google/googletest && \
5753
cd googletest && \
5854
mkdir build && cd build && \
@@ -84,12 +80,11 @@ RUN APT_INSTALL="apt-get install -y --no-install-recommends" && \
8480
mkdir -p build && cd build && \
8581
cmake .. -DCMAKE_BUILD_TYPE=Release -DFLASHLIGHT_BACKEND=CUDA && \
8682
make -j8 && \
87-
make install && \
83+
make install && \
8884
# ========================================================= =========
8985
# config & cleanup
9086
# ------------------------------------------------------------------
9187
ldconfig && \
9288
apt-get clean && \
9389
apt-get autoremove && \
9490
rm -rf /var/lib/apt/lists/* /tmp/* ~/*
95-

LICENSE

-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
SOFTWARE.
22-
23-
24-
25-

cmake/FindGFLAGS.cmake

-29
This file was deleted.

cmake/FindGLOG.cmake

-31
This file was deleted.

docs/source/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Dependencies
2323
flashlight can be built with either a CUDA, CPU (coming soon), or OpenCL (coming soon) backend. Requirements vary depending on which backend is selected. All dependencies must be built/installed before building flashlight.
2424

2525
- For all backends, `ArrayFire <https://github.com/arrayfire/arrayfire/wiki>`_ >= 3.6.1 is required. flashlight has been tested with `ArrayFire 3.6.1 <https://github.com/arrayfire/arrayfire/releases/tag/v3.6.1>`_.
26-
- `Cereal <https://github.com/USCiLab/cereal>`_ is required for serialization -- the ``develop`` branch must be used.
26+
- `Cereal <https://github.com/USCiLab/cereal> `_ is required for serialization -- the `develop` branch must be used.
2727
- If building tests, `Google Test <https://github.com/google/googletest>`_ >= 1.8.0 is required -- Google Test is downloaded and built when building flashlight with tests.
2828

2929
Distributed Training Dependencies

examples/Mnist.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include <iomanip>
2424
#include <iostream>
25+
#include <stdexcept>
2526

2627
#include <arrayfire.h>
2728
#include <flashlight/flashlight.h>

examples/RnnLm.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
#include <iomanip>
2525
#include <iostream>
26+
#include <stdexcept>
2627
#include <unordered_map>
2728
#include <vector>
2829

@@ -86,8 +87,12 @@ class RnnLm : public Container {
8687
add(LogSoftmax());
8788
}
8889

89-
Variable forward(const Variable& input) override {
90-
return std::get<0>(forward(input, Variable(), Variable()));
90+
std::vector<Variable> forward(const std::vector<Variable>& inputs) override {
91+
auto inSz = inputs.size();
92+
if (inSz < 1 || inSz > 3) {
93+
throw std::invalid_argument("Invalid inputs size");
94+
}
95+
return rnn(inputs);
9196
}
9297

9398
std::tuple<Variable, Variable, Variable>

flashlight/autograd/Functions.cpp

+23-27
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
#include <algorithm>
1717
#include <array>
18+
#include <stdexcept>
1819

1920
#include <af/internal.h>
2021

21-
#include <flashlight/common/Exception.h>
2222
#include "Functions.h"
2323
#include "Variable.h"
2424

@@ -426,22 +426,19 @@ Variable sumAs(const Variable& input, const Variable& reference) {
426426

427427
Variable concatenate(const std::vector<Variable>& concatInputs, int dim) {
428428
if (concatInputs.empty()) {
429-
AFML_THROW_ERR(
430-
"[Variable concatenate] Need at least one variable.", AF_ERR_ARG);
429+
throw std::invalid_argument("cannot concatenate zero variables");
431430
}
432431
if (dim < 0 || dim > 3) {
433-
AFML_THROW_ERR("[Variable concatenate] Invalid dimension.", AF_ERR_ARG);
432+
throw std::invalid_argument("invalid dimension to concatenate along");
434433
}
435434
auto dims = concatInputs[0].dims();
436435
int concat_size = dims[dim];
437436
for (int i = 1; i < concatInputs.size(); i++) {
438437
concat_size += concatInputs[i].dims(dim);
439438
for (int d = 0; d < 4; d++) {
440439
if (dim != d && concatInputs[i].dims(d) != dims[d]) {
441-
AFML_THROW_ERR(
442-
"[Variable concatenate] Mismatch in dimension "
443-
"not being concatenated.",
444-
AF_ERR_ARG);
440+
throw std::invalid_argument(
441+
"mismatch in dimension not being concatenated");
445442
}
446443
}
447444
}
@@ -531,8 +528,10 @@ Variable var(
531528
for (auto ax : axes) {
532529
n *= input.dims(ax);
533530
}
534-
AFML_ASSERT(
535-
isbiased || n > 1, "Division by zero when computing var", AF_ERR_SIZE)
531+
if (!isbiased && n == 1) {
532+
throw std::invalid_argument(
533+
"cannot compute unbiased variance with only one sample");
534+
}
536535
auto val = 1.0 / (isbiased ? n : n - 1);
537536
result = val * (result - n * avg * avg);
538537
auto gradFunc =
@@ -688,15 +687,13 @@ Variable moddims(const Variable& input, const af::dim4& dims) {
688687
}
689688
}
690689

691-
AFML_ASSERT(
692-
n_infer <= 1,
693-
"[Variable moddims] Only infer a single dimension",
694-
AF_ERR_ARG);
690+
if (n_infer > 1) {
691+
throw std::invalid_argument("too many dimensions for moddims to infer");
692+
}
695693

696-
AFML_ASSERT(
697-
infer_dims.elements() == input.elements(),
698-
"[Variable moddims] Number of elements must match.",
699-
AF_ERR_ARG);
694+
if (infer_dims.elements() != input.elements()) {
695+
throw std::invalid_argument("mismatched # of elements in moddims");
696+
}
700697

701698
auto result = af::moddims(input.array(), infer_dims);
702699

@@ -760,15 +757,13 @@ Variable categoricalCrossEntropy(
760757
// target -- [X1, X2, X3, 1]
761758
for (int i = 1; i < 4; i++) {
762759
if (input.dims(i) != targets.dims(i - 1)) {
763-
AFML_THROW_ERR(
764-
"[categoricalCrossEntropy] Size mismatch between input and target.",
765-
AF_ERR_ARG);
760+
throw std::invalid_argument(
761+
"dimension mismatch in categorical cross entropy");
766762
}
767763
}
768764
if (targets.dims(3) != 1) {
769-
AFML_THROW_ERR(
770-
"[categoricalCrossEntropy] Size mismatch between input and target.",
771-
AF_ERR_ARG);
765+
throw std::invalid_argument(
766+
"dimension mismatch in categorical cross entropy");
772767
}
773768

774769
int categories = input.dims(0);
@@ -789,7 +784,8 @@ Variable categoricalCrossEntropy(
789784
} else if (reduction == ReduceMode::SUM) {
790785
result = af::sum(result, 1);
791786
} else {
792-
AFML_THROW_ERR("[nLLLoss] Invalid reduction method.", AF_ERR_ARG);
787+
throw std::invalid_argument(
788+
"unknown reduction method for categorical cross entropy");
793789
}
794790

795791
af::dim4 in_dims = input.dims();
@@ -898,7 +894,7 @@ linear(const Variable& input, const Variable& weight, const Variable& bias) {
898894
Variable gatedlinearunit(const Variable& input, const int dim) {
899895
auto in_size = input.dims(dim);
900896
if (in_size % 2 == 1) {
901-
AFML_THROW_ERR("Halving dimension needs to be even for GLU.", AF_ERR_ARG);
897+
throw std::invalid_argument("halving dimension must be even for GLU");
902898
}
903899
std::array<af::seq, 4> fhalf = {af::span, af::span, af::span, af::span};
904900
fhalf[dim] = af::seq(in_size / 2);
@@ -928,7 +924,7 @@ Variable gatedlinearunit(const Variable& input, const int dim) {
928924

929925
Variable embedding(const Variable& input, const Variable& embeddings) {
930926
if (input.numdims() >= 4) {
931-
AFML_THROW_ERR("[embedding] Input must have 3 or fewer dims.", AF_ERR_ARG);
927+
throw std::invalid_argument("embedding input must have 3 or fewer dims");
932928
}
933929

934930
auto idxs = af::flat(input.array());

0 commit comments

Comments
 (0)