Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update FG for latest paddle and cuda #6812

Merged
merged 21 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions paddlenlp/ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ endif()

INCLUDE(ExternalProject)

set(CXX_STD "14" CACHE STRING "C++ standard")
set(CXX_STD "17" CACHE STRING "C++ standard")

option(ON_INFER "Compiled with inference. " OFF)
option(WITH_GPU "Compiled with GPU/CPU, default use CPU." ON)
Expand Down Expand Up @@ -248,8 +248,8 @@ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -O0")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0")
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -O0 -G -Xcompiler -Wall")

set(CMAKE_CXX_STANDARD "${CXX_STD}")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++{CXX_STD}")
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++{CXX_STD}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --std=c++${CXX_STD}")
Expand Down Expand Up @@ -387,6 +387,8 @@ file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/${THIRD_PATH}/source/${THIRD_PARTY_NAME}
set(MUTE_COMMAND grep -rl "printf(\"\\[WARNING\\]" ${CMAKE_BINARY_DIR}/${THIRD_PATH}/source/${THIRD_PARTY_NAME}/ | xargs -i{} sed -i "s/printf(\"\\WWARNING\\W decoding[^)]\\{1,\\})/ /" {})
set(OPEN_ATTENTION_MUTE_COMMAND grep -rl "printf(\"\\[WARNING\\]" ${CMAKE_BINARY_DIR}/${THIRD_PATH}/source/${THIRD_PARTY_NAME}/ | xargs -i{} sed -i "s/printf(\"\\WWARNING\\W\\WOpenMultiHeadAttention\\W[^)]\\{1,\\})/ /" {})

set(RM_OLD_CUB_COMMAND rm -rf ${CMAKE_BINARY_DIR}/${THIRD_PATH}/source/${THIRD_PARTY_NAME}/fastertransformer/cuda/cub)

set(FT_PATCH_COMMAND
printf \\n\\n > blank_lines
&& cp ${allocator_src} ${allocator_dst}
Expand Down Expand Up @@ -428,6 +430,7 @@ set(FT_PATCH_COMMAND
&& rm blank_lines
&& ${MUTE_COMMAND}
&& ${OPEN_ATTENTION_MUTE_COMMAND}
&& ${RM_OLD_CUB_COMMAND}
)

# TODO(guosheng): Use UPDATE_COMMAND instead of PATCH_COMMAND to make cmake
Expand All @@ -438,14 +441,14 @@ set(FT_UPDATE_COMMAND git checkout nccl_dependent_refine && git checkout . && ${

ExternalProject_Add(
extern_${THIRD_PARTY_NAME}
GIT_REPOSITORY https://gitee.com/paddlepaddle/FasterTransformer.git
GIT_REPOSITORY https://github.com/NVIDIA/FasterTransformer.git
GIT_TAG nccl_dependent_refine
PREFIX ${THIRD_PATH}
SOURCE_DIR ${THIRD_PATH}/source/${THIRD_PARTY_NAME}
UPDATE_COMMAND ${FT_UPDATE_COMMAND} # PATCH_COMMAND ${FT_PATCH_COMMAND}
BINARY_DIR ${THIRD_PATH}/build/${THIRD_PARTY_NAME}
INSTALL_COMMAND ""
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DSM=${SM} -DBUILD_PD=ON -DBUILD_ENCODER=${WITH_ENCODER} -DPY_CMD=${PY_CMD} -DON_INFER=${ON_INFER} -DPADDLE_LIB=${PADDLE_LIB} -DWITH_MKL=${WITH_MKL} -DWITH_STATIC_LIB=${WITH_STATIC_LIB} -DBUILD_GPT=${WITH_PARALLEL} -DWITH_ONNXRUNTIME=${WITH_ONNXRUNTIME}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_C_COMPILER=/usr/local/gcc-12.2/bin/gcc -DCMAKE_CXX_COMPILER=/usr/local/gcc-12.2/bin/g++ -DSM=${SM} -DBUILD_PD=ON -DBUILD_ENCODER=${WITH_ENCODER} -DPY_CMD=${PY_CMD} -DON_INFER=${ON_INFER} -DPADDLE_LIB=${PADDLE_LIB} -DWITH_MKL=${WITH_MKL} -DWITH_STATIC_LIB=${WITH_STATIC_LIB} -DBUILD_GPT=${WITH_PARALLEL} -DWITH_ONNXRUNTIME=${WITH_ONNXRUNTIME}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的CMAKE_CXX_COMPILER是否要明确写死这个路径了

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改,通过环境变量设置gcc和g++

)
# -DBUILD_GPT=${WITH_GPT}
ExternalProject_Get_property(extern_${THIRD_PARTY_NAME} BINARY_DIR)
Expand Down
13 changes: 12 additions & 1 deletion paddlenlp/ops/ext_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import distutils
import functools
import hashlib
import os
Expand Down Expand Up @@ -144,6 +145,8 @@
# CMake 3.12+ only.
build_args += ["-j{}".format(ext_builder.parallel)]

build_args += ["-j14"]

Check warning on line 148 in paddlenlp/ops/ext_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/ops/ext_utils.py#L148

Added line #L148 was not covered by tests

if not os.path.exists(ext_builder.build_temp):
os.makedirs(ext_builder.build_temp)

Expand Down Expand Up @@ -198,9 +201,17 @@
# `GetCUDAComputeCapability` is not exposed yet, and detect CUDA/GPU
# version in cmake file.
# self.cmake_args += [f"-DSM={self.sm}"] if self.sm is not None else []
self.cmake_args += ["-DWITH_GPT=ON"]
self.cmake_args += "-DWITH_GPT=ON -DON_INFER=OFF -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON".split()

Check warning on line 204 in paddlenlp/ops/ext_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/ops/ext_utils.py#L204

Added line #L204 was not covered by tests

self.cmake_args += ["-DCMAKE_C_COMPILER={}".format(os.getenv("C_COMPILER_PATH"))]
self.cmake_args += ["-DCMAKE_CXX_COMPILER={}".format(os.getenv("CXX_COMPILER_PATH"))]

Check warning on line 207 in paddlenlp/ops/ext_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/ops/ext_utils.py#L206-L207

Added lines #L206 - L207 were not covered by tests

self.cmake_args += ["-DPYTHON_LIBRARY={}".format(distutils.sysconfig.get_config_var("LIBDIR"))]
self.cmake_args += ["-DPYTHON_INCLUDE_DIR={}".format(distutils.sysconfig.get_python_inc())]

Check warning on line 210 in paddlenlp/ops/ext_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/ops/ext_utils.py#L209-L210

Added lines #L209 - L210 were not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否可以直接使用sysconfig的一些方法拿到了,distutils之前因为deprecated有想要去掉

# copy form distutils.dep_util to avoid import distutils
def newer_group(sources, target, missing="error"):
    """Return true if 'target' is out-of-date with respect to any file
    listed in 'sources'.  In other words, if 'target' exists and is newer
    than every file in 'sources', return false; otherwise return true

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已经修改,distutils.sysconfig功能已经导入sysconfig,直接使用import sysconfig并实现了相同输出


if self.need_parallel:
self.cmake_args += ["-DWITH_PARALLEL=ON"]

try:
super(FasterTransformerExtension, self).build_with_command(ext_builder)
# FastGeneration cmake file resets `CMAKE_LIBRARY_OUTPUT_DIRECTORY`
Expand Down
6 changes: 3 additions & 3 deletions paddlenlp/ops/fast_transformer/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ if(ON_INFER)
message(FATAL_ERROR "please set DEMO with -DDEMO=demo_name")
endif()

include_directories("${PADDLE_LIB}/")
include_directories("${PADDLE_LIB}/paddle/include")
set(PADDLE_LIB_THIRD_PARTY_PATH "${PADDLE_LIB}/third_party/install/")
include_directories("${PADDLE_LIB_THIRD_PARTY_PATH}protobuf/include")
include_directories("${PADDLE_LIB_THIRD_PARTY_PATH}glog/include")
Expand Down Expand Up @@ -89,7 +89,7 @@ if(ON_INFER)
if(WITH_MKL)
set(FLAG_OPENMP "-fopenmp")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 ${FLAG_OPENMP}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FLAG_OPENMP}")
endif()

if (USE_TENSORRT AND WITH_GPU)
Expand Down Expand Up @@ -124,7 +124,7 @@ if(ON_INFER)
if(WIN32)
set(MKLDNN_LIB ${MKLDNN_PATH}/lib/mkldnn.lib)
else(WIN32)
set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libmkldnn.so.0)
set(MKLDNN_LIB ${MKLDNN_PATH}/lib/libdnnl.so.3)
endif(WIN32)
endif()
else()
Expand Down
10 changes: 5 additions & 5 deletions paddlenlp/ops/fast_transformer/src/demo/gpt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <pthread.h>
#include <algorithm>
#include <atomic>
#include <codecvt>
#include <string>
#include <cstring>
#include <fstream>
#include <iostream>
Expand All @@ -30,6 +30,7 @@
#endif

#include "helper.h"
#include "utf8.h"

#include <sys/time.h>
#include <unistd.h>
Expand Down Expand Up @@ -58,7 +59,6 @@ const int BOS_IDX = 50256;
const int EOS_IDX = 50256;
const int PAD_IDX = 50256;
const int MAX_LENGTH = 256;
std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert;

int batch_size = 1;
int gpu_id = 0;
Expand Down Expand Up @@ -186,7 +186,7 @@ class DataReader {
std::string line;
int k = 0;
while (std::getline(fin, line)) {
std::u32string tmp = convert.from_bytes(line);
std::u32string tmp = utf8::utf8to32(line);
word2num_dict[tmp] = k;
num2word_dict[k] = tmp;
k += 1;
Expand Down Expand Up @@ -314,8 +314,8 @@ int main(int argc, char** argv) {

paddle::inference::Main(batch_size,
gpu_id,
convert.from_bytes(FLAGS_start_token),
convert.from_bytes(FLAGS_end_token));
utf8::utf8to32(FLAGS_start_token),
utf8::utf8to32(FLAGS_end_token));

return 0;
}
2 changes: 1 addition & 1 deletion paddlenlp/ops/fast_transformer/src/demo/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ limitations under the License. */
#include <sstream>
#include <string>
#include <vector>
#include "paddle/include/paddle_inference_api.h"
#include "paddle_inference_api.h"

namespace paddle {
namespace inference {
Expand Down
34 changes: 34 additions & 0 deletions paddlenlp/ops/fast_transformer/src/demo/utf8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2006 Nemanja Trifunovic

/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/


#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731

#include "utf8/checked.h"
#include "utf8/unchecked.h"

#endif // header guard