Repository: PaddlePaddle/PaddleNLP
Pull request: Update FG for latest paddle and cuda
<!-- Demo: https://github.com/PaddlePaddle/PaddleNLP/pull/26 -->
### PR types
<!-- One of [ New features | Bug fixes | Function optimization | Performance optimization | Breaking changes | Others ] -->
Bug fixes

### PR changes
<!-- One of [ Models | APIs | Docs | Others ] -->
Others

### Description
<!-- Describe what this PR does -->
* update -std=c++17 in `CMakeList.txt` for latest paddle inference libary.
* update include files in `paddlenlp/ops/fast_transformer/src/xxx.h` for latest paddle inference libary.
* replace `codecvt` with [`utf8cpp`](https://github.com/nemtrif/utfcpp.git) in `demo/gpt.cc`, since `codecvt` is deprecated in C++17. 
* config `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` in `ci_case.sh` to avoid system gcc 4.8.5 during `cmake`.



This resolves https://github.com/PaddlePaddle/PaddleNLP/issues/3522 

Problem statement:
[Question]: 中文摘要模型export加速build出错
中文摘要unimo模型导出静态图模式报错：

> [2022-10-20` 15:15:01,602] [    INFO] - Already cached C:\Users\wangyiting\.paddlenlp\models\unimo-text-1.0-summary\unimo-text-1.0-summary.pdparams
W1020 15:15:01.602730 63484 gpu_resources.cc:61] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 11.6, Runtime API Version: 11.2
W1020 15:15:01.607863 63484 gpu_resources.cc:91] device: 0, cuDNN Version: 8.4.
Namespace(decoding_strategy='beam_search', diversity_rate=0.0, inference_model_dir='./inference_model', max_out_len=64, min_out_len=1, model_name_or_path='unimo-text-1.0-summary', num_beams=4, num_return_sequence=1, num_return_sequences=1, temperature=1.0, topk=4, topp=1.0, use_fp16_decoding=False)
[2022-10-20 15:15:04,724] [    INFO] - Already cached C:\Users\wangyiting\.paddlenlp\models\unimo-text-1.0-summary\unimo-text-1.0-vocab.txt
[2022-10-20 15:15:04,746] [    INFO] - tokenizer config file saved in C:\Users\wangyiting\.paddlenlp\models\unimo-text-1.0-summary\tokenizer_config.json
[2022-10-20 15:15:04,747] [    INFO] - Special tokens file saved in C:\Users\wangyiting\.paddlenlp\models\unimo-text-1.0-summary\special_tokens_map.json
2022-10-20 15:15:04,813 - INFO - Using Python interpreter: C:\Users\wangyiting\Anaconda3\envs\paddlenlp\python.exe, version: Python 3.7.13
2022-10-20 15:15:04,813 - INFO - execute command: cd /d C:\Users\wangyiting\.paddlenlp\extensions\c60d8357021ebfe66404f37228b38a6c\FasterTransformer && C:\Users\wangyiting\Anaconda3\envs\paddlenlp\python.exe FasterTransformer_setup.py build
Compiling user custom op, it will cost a few seconds.....
running build
running build_ext
[2022-10-20 15:15:07,275] [ WARNING] - FasterTransformer is not available due to build errors.
Traceback (most recent call last):
  File "FasterTransformer_setup.py", line 11, in <module>
    output_dir=r'C:\Users\wangyiting\.paddlenlp\extensions\c60d8357021ebfe66404f37228b38a6c\FasterTransformer')
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
    return run_commands(dist)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
    dist.run_commands()
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\dist.py", line 973, in run_commands
    self.run_command(cmd)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\dist.py", line 1217, in run_command
    super().run_command(command)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\dist.py", line 992, in run_command
    cmd_obj.run()
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\command\build.py", line 24, in run
    super().run()
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\command\build.py", line 132, in run
    self.run_command(cmd_name)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\cmd.py", line 319, in run_command
    self.distribution.run_command(command)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\dist.py", line 1217, in run_command
    super().run_command(command)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\dist.py", line 992, in run_command
    cmd_obj.run()
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\command\build_ext.py", line 79, in run
    _build_ext.run(self)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\setuptools\_distutils\command\build_ext.py", line 346, in run
    self.build_extensions()
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\ext_utils.py", line 193, in build_extensions
    ext.build_with_command(self)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\ext_utils.py", line 171, in build_with_command
    raise e
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\ext_utils.py", line 158, in build_with_command
    self).build_with_command(ext_builder)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\ext_utils.py", line 75, in build_with_command
    raise NotImplementedError
NotImplementedError
Traceback (most recent call last):
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddle\utils\cpp_extension\extension_utils.py", line 1148, in run_cmd
    command, shell=True, stderr=subprocess.STDOUT)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'cd /d C:\Users\wangyiting\.paddlenlp\extensions\c60d8357021ebfe66404f37228b38a6c\FasterTransformer && C:\Users\wangyiting\Anaconda3\envs\paddlenlp\python.exe FasterTransformer_setup.py build' returned non-zero exit status 1.

> During handling of the above exception, another exception occurred:

> Traceback (most recent call last):

  File "C:/Users/wangyiting/Documents/研二/code/ernie/PaddleNLP/applications/text_summarization/export_model.py", line 142, in <module>
    do_predict(args)
  File "C:/Users/wangyiting/Documents/研二/code/ernie/PaddleNLP/applications/text_summarization/export_model.py", line 99, in do_predict
    trans_out=True)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\transformers\utils.py", line 159, in __impl__
    init_func(self, *args, **kwargs)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\faster_transformer\transformer\faster_transformer.py", line 1142, in __init__
    hidden_act=self._hidden_act)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\faster_transformer\transformer\decoding.py", line 1913, in __init__
    need_parallel=not get_ft_para_conf().no_para)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\utils\file_lock.py", line 113, in _impl
    func(*args, **kwargs)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddlenlp\ops\ext_utils.py", line 310, in load
    _jit_compile(file_path, verbose)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddle\utils\cpp_extension\extension_utils.py", line 1112, in _jit_compile
    run_cmd(compile_cmd, verbose)
  File "C:\Users\wangyiting\Anaconda3\envs\paddlenlp\lib\site-packages\paddle\utils\cpp_extension\extension_utils.py", line 1154, in run_cmd
    compile, error))
RuntimeError: Failed to run command: <built-in function compile>, errors: Command 'cd /d C:\Users\wangyiting\.paddlenlp\extensions\c60d8357021ebfe66404f37228b38a6c\FasterTransformer && C:\Users\wangyiting\Anaconda3\envs\paddlenlp\python.exe FasterTransformer_setup.py build' returned non-zero exit status 1.

Process finished with exit code 1

Hints from issue discussion:
请问您那边是Windows环境是吗
你好，windows暂时不支持，目前支持的环境为Linux+CUDA
对windows环境，好的换成服务器了，在linux环境下执行报错，请问可以帮忙看下是哪里的问题吗，谢谢

> Scanning dependencies of target cuda_kernels
[  2%] Building CUDA object fastertransformer/cuda/CMakeFiles/cuda_kernels.dir/cuda_kernels.cu.o
nvcc warning : The -std=c++14 flag is not supported with the configured host compiler. Flag will be ignored.
In file included from /usr/include/c++/4.8.2/array:35:0,
                 from /data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/topk_kernels.cuh:18,
                 from /data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/cuda_kernels.h:21,
                 from /data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/cuda_kernels.cu:18:
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support for the \
  ^
gmake[5]: *** [fastertransformer/cuda/CMakeFiles/cuda_kernels.dir/cuda_kernels.cu.o] Error 1
gmake[4]: *** [fastertransformer/cuda/CMakeFiles/cuda_kernels.dir/all] Error 2
gmake[3]: *** [all] Error 2
gmake[2]: *** [third-party/src/extern_fastertransformer-stamp/extern_fastertransformer-build] Error 2
gmake[1]: *** [CMakeFiles/extern_fastertransformer.dir/all] Error 2
gmake: *** [all] Error 2
[2022-10-20 17:25:01,230] [ WARNING] - FasterTransformer is not available due to build errors.
Traceback (most recent call last):
  File "FasterTransformer_setup.py", line 11, in <module>
    output_dir=r'/data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer')
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 973, in run_commands
    self.run_command(cmd)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
    cmd_obj.run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/command/build.py", line 24, in run
    super().run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/command/build.py", line 132, in run
    self.run_command(cmd_name)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 319, in run_command
    self.distribution.run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
    cmd_obj.run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 79, in run
    _build_ext.run(self)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/command/build_ext.py", line 346, in run
    self.build_extensions()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 193, in build_extensions
    ext.build_with_command(self)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 171, in build_with_command
    raise e
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 158, in build_with_command
    self).build_with_command(ext_builder)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 104, in build_with_command
    stderr=stdout)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.']' returned non-zero exit status 2.
Traceback (most recent call last):
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddle/utils/cpp_extension/extension_utils.py", line 1148, in run_cmd
    command, shell=True, stderr=subprocess.STDOUT)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command 'cd /data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer && /data/users/wangyiting/anaconda3/envs/python37/bin/python FasterTransformer_setup.py build' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "export_model.py", line 142, in <module>
    do_predict(args)
  File "export_model.py", line 99, in do_predict
    trans_out=True)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/transformers/utils.py", line 159, in __impl__
    init_func(self, *args, **kwargs)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/faster_transformer/transformer/faster_transformer.py", line 1142, in __init__
    hidden_act=self._hidden_act)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/faster_transformer/transformer/decoding.py", line 1913, in __init__
    need_parallel=not get_ft_para_conf().no_para)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/utils/file_lock.py", line 113, in _impl
    func(*args, **kwargs)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 310, in load
    _jit_compile(file_path, verbose)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddle/utils/cpp_extension/extension_utils.py", line 1112, in _jit_compile
    run_cmd(compile_cmd, verbose)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddle/utils/cpp_extension/extension_utils.py", line 1154, in run_cmd
    compile, error))
RuntimeError: Failed to run command: <built-in function compile>, errors: Command 'cd /data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer && /data/users/wangyiting/anaconda3/envs/python37/bin/python FasterTransformer_setup.py build' returned non-zero exit status 1.
/usr/include/c++/4.8.2/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
可能是这里，请问是指什么版本不对吗
可能是gcc/g++版本低了，设置的`-std=c++14`不支持没生效，但是要求的`-std=c++11`  这个没设置，可以换个高版本的gcc/g++试下呢，或者可以试下Paddle官方的docker镜像 https://www.paddlepaddle.org.cn/install/quick?docurl=/documentation/docs/zh/install/docker/linux-docker.html
请问gcc版本要求多少呢？版本太多了不太好配谢谢
安装gcc5.1.0，又报了新的错误：

> [ 64%] Building CUDA object fastertransformer/cuda/CMakeFiles/decoder.dir/open_decoder.cu.o
/data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/open_decoder.cu(303): warning: specified alignment (2) is different from alignment (4) specified on a previous declaration
          detected during:
            instantiation of "void fastertransformer::masked_attention_kernel(T *, T *, T *, const T *, T *, const T *, T *, const T *, T *, const __nv_bool *, int, int, int, int, T) [with T=half]" 
(445): here
            instantiation of "void fastertransformer::masked_attention_dispatch(T *, T *, T *, const T *, T *, const T *, T *, const T *, T *, const __nv_bool *, int, int, int, int, int, int, cudaStream_t) [with T=half]" 
(503): here

/data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/open_decoder.cu(1420): warning: specified alignment (2) is different from alignment (4) specified on a previous declaration
          detected during:
            instantiation of "void fastertransformer::cross_attention_kernel(T *, const T *, T *, const T *, T *, const T *, const int *, T *, const __nv_bool *, int, int, int, int, int, T) [with T=half]" 
(1555): here
            instantiation of "void fastertransformer::cross_attention_dispatch(T *, const T *, T *, const T *, T *, const T *, const int *, T *, const __nv_bool *, int, int, int, int, int, cudaStream_t) [with T=half]" 
(1576): here

[ 66%] Building CUDA object fastertransformer/cuda/CMakeFiles/decoder.dir/masked_multihead_attention.cu.o
/data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer/build/temp.linux-x86_64-cpython-37/third-party/source/fastertransformer/fastertransformer/cuda/masked_multihead_attention.cu(1113): error: expected a comma (the one-argument version of static_assert is not enabled in this mode)
          detected during:
            instantiation of "void mmha_launch_kernel<T,Dh,Dh_MAX>(const Masked_multihead_attention_params<T> &, const cudaStream_t &) [with T=float, Dh=32, Dh_MAX=32]" 
(1458): here
            instantiation of "void masked_multihead_attention_(const Masked_multihead_attention_params<T> &, const cudaStream_t &) [with T=float]" 
(1493): here

1 error detected in the compilation of "/tmp/tmpxft_00015974_00000000-6_masked_multihead_attention.cpp1.ii".
gmake[5]: *** [fastertransformer/cuda/CMakeFiles/decoder.dir/masked_multihead_attention.cu.o] Error 1
gmake[4]: *** [fastertransformer/cuda/CMakeFiles/decoder.dir/all] Error 2
gmake[3]: *** [all] Error 2
gmake[2]: *** [third-party/src/extern_fastertransformer-stamp/extern_fastertransformer-build] Error 2
gmake[1]: *** [CMakeFiles/extern_fastertransformer.dir/all] Error 2
gmake: *** [all] Error 2
[2022-10-25 20:58:20,649] [ WARNING] - FasterTransformer is not available due to build errors.
Traceback (most recent call last):
  File "FasterTransformer_setup.py", line 11, in <module>
    output_dir=r'/data/users/wangyiting/.paddlenlp/extensions/ab3fb0c16468d26c231f6e4b0d565ac0/FasterTransformer')
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/__init__.py", line 87, in setup
    return distutils.core.setup(**attrs)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 185, in setup
    return run_commands(dist)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/core.py", line 201, in run_commands
    dist.run_commands()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 973, in run_commands
    self.run_command(cmd)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
    cmd_obj.run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/command/build.py", line 24, in run
    super().run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/command/build.py", line 132, in run
    self.run_command(cmd_name)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/cmd.py", line 319, in run_command
    self.distribution.run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/dist.py", line 1217, in run_command
    super().run_command(command)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/dist.py", line 992, in run_command
    cmd_obj.run()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/command/build_ext.py", line 79, in run
    _build_ext.run(self)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/setuptools/_distutils/command/build_ext.py", line 346, in run
    self.build_extensions()
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 193, in build_extensions
    ext.build_with_command(self)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 171, in build_with_command
    raise e
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 158, in build_with_command
    self).build_with_command(ext_builder)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/site-packages/paddlenlp/ops/ext_utils.py", line 104, in build_with_command
    stderr=stdout)
  File "/data/users/wangyiting/anaconda3/envs/python37/lib/python3.7/subprocess.py", line 363, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.']' returned non-zero exit status 2.
主要是服务器没有root权限无法运行nvidia-docker
或者可以提供加速后的模型文件供下载吗 感谢
你好，gcc可以升级到8.2。最好是本机编译通过，机器环境不同，编译出来效果有差别。
我也是这个unimo中文模型，请问下能否不用fastertransformer的方式部署呢（https://github.com/PaddlePaddle/PaddleNLP/tree/develop/applications/text_summarization/unimo-text/deploy/paddle_inference） ， 环境是windows+CUDA11.6+cudnn8.4，直接用train里的预测速度太慢了

Commit message: update

Patch to review:
diff --git a/paddlenlp/ops/CMakeLists.txt b/paddlenlp/ops/CMakeLists.txt
index fb73814be68e..b54bec507b97 100644
--- a/paddlenlp/ops/CMakeLists.txt
+++ b/paddlenlp/ops/CMakeLists.txt
@@ -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)
@@ -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}")
@@ -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}
@@ -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
@@ -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}
 )
 # -DBUILD_GPT=${WITH_GPT} 
 ExternalProject_Get_property(extern_${THIRD_PARTY_NAME} BINARY_DIR)
diff --git a/paddlenlp/ops/ext_utils.py b/paddlenlp/ops/ext_utils.py
index 00df3b9eb253..0496105f2676 100644
--- a/paddlenlp/ops/ext_utils.py
+++ b/paddlenlp/ops/ext_utils.py
@@ -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
@@ -144,6 +145,8 @@ def build_with_command(self, ext_builder):
                 # CMake 3.12+ only.
                 build_args += ["-j{}".format(ext_builder.parallel)]
 
+        build_args += ["-j14"]
+
         if not os.path.exists(ext_builder.build_temp):
             os.makedirs(ext_builder.build_temp)
 
@@ -198,9 +201,17 @@ def build_with_command(self, ext_builder):
         # `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()
+
+        self.cmake_args += ["-DCMAKE_C_COMPILER={}".format(os.getenv("C_COMPILER_PATH"))]
+        self.cmake_args += ["-DCMAKE_CXX_COMPILER={}".format(os.getenv("CXX_COMPILER_PATH"))]
+
+        self.cmake_args += ["-DPYTHON_LIBRARY={}".format(distutils.sysconfig.get_config_var("LIBDIR"))]
+        self.cmake_args += ["-DPYTHON_INCLUDE_DIR={}".format(distutils.sysconfig.get_python_inc())]
+
         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`
diff --git a/paddlenlp/ops/fast_transformer/src/CMakeLists.txt b/paddlenlp/ops/fast_transformer/src/CMakeLists.txt
index eb9f6bc66f2f..cc74cfe693c3 100644
--- a/paddlenlp/ops/fast_transformer/src/CMakeLists.txt
+++ b/paddlenlp/ops/fast_transformer/src/CMakeLists.txt
@@ -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")
@@ -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)
@@ -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()
diff --git a/paddlenlp/ops/fast_transformer/src/demo/gpt.cc b/paddlenlp/ops/fast_transformer/src/demo/gpt.cc
index ad80624aeca9..7dd55efb2c7a 100644
--- a/paddlenlp/ops/fast_transformer/src/demo/gpt.cc
+++ b/paddlenlp/ops/fast_transformer/src/demo/gpt.cc
@@ -15,7 +15,7 @@
 #include <pthread.h>
 #include <algorithm>
 #include <atomic>
-#include <codecvt>
+#include <string>
 #include <cstring>
 #include <fstream>
 #include <iostream>
@@ -30,6 +30,7 @@
 #endif
 
 #include "helper.h"
+#include "utf8.h"
 
 #include <sys/time.h>
 #include <unistd.h>
@@ -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;
@@ -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;
@@ -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;
 }
diff --git a/paddlenlp/ops/fast_transformer/src/demo/helper.h b/paddlenlp/ops/fast_transformer/src/demo/helper.h
index e05a33bf18e7..046ca4c9e3ea 100644
--- a/paddlenlp/ops/fast_transformer/src/demo/helper.h
+++ b/paddlenlp/ops/fast_transformer/src/demo/helper.h
@@ -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 {
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8.h b/paddlenlp/ops/fast_transformer/src/demo/utf8.h
new file mode 100644
index 000000000000..82b13f59f983
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8.h
@@ -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
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8/checked.h b/paddlenlp/ops/fast_transformer/src/demo/utf8/checked.h
new file mode 100644
index 000000000000..512dcc2fbac8
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8/checked.h
@@ -0,0 +1,319 @@
+// Copyright 2006-2016 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_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+#define UTF8_FOR_CPP_CHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+
+#include "core.h"
+#include <stdexcept>
+
+namespace utf8
+{
+    // Base for the exceptions that may be thrown from the library
+    class exception : public ::std::exception {
+    };
+
+    // Exceptions that may be thrown from the library functions.
+    class invalid_code_point : public exception {
+        uint32_t cp;
+    public:
+        invalid_code_point(uint32_t codepoint) : cp(codepoint) {}
+        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid code point"; }
+        uint32_t code_point() const {return cp;}
+    };
+
+    class invalid_utf8 : public exception {
+        uint8_t u8;
+    public:
+        invalid_utf8 (uint8_t u) : u8(u) {}
+        invalid_utf8 (char c) : u8(static_cast<uint8_t>(c)) {}
+        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-8"; }
+        uint8_t utf8_octet() const {return u8;}
+    };
+
+    class invalid_utf16 : public exception {
+        uint16_t u16;
+    public:
+        invalid_utf16 (uint16_t u) : u16(u) {}
+        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Invalid UTF-16"; }
+        uint16_t utf16_word() const {return u16;}
+    };
+
+    class not_enough_room : public exception {
+    public:
+        virtual const char* what() const UTF_CPP_NOEXCEPT UTF_CPP_OVERRIDE { return "Not enough space"; }
+    };
+
+    /// The library API - functions intended to be called by the users
+
+    template <typename octet_iterator>
+    octet_iterator append(uint32_t cp, octet_iterator result)
+    {
+        if (!utf8::internal::is_code_point_valid(cp))
+            throw invalid_code_point(cp);
+
+        return internal::append(cp, result);
+    }
+
+    template <typename octet_iterator, typename output_iterator>
+    output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
+    {
+        while (start != end) {
+            octet_iterator sequence_start = start;
+            internal::utf_error err_code = utf8::internal::validate_next(start, end);
+            switch (err_code) {
+                case internal::UTF8_OK :
+                    for (octet_iterator it = sequence_start; it != start; ++it)
+                        *out++ = *it;
+                    break;
+                case internal::NOT_ENOUGH_ROOM:
+                    out = utf8::append (replacement, out);
+                    start = end;
+                    break;
+                case internal::INVALID_LEAD:
+                    out = utf8::append (replacement, out);
+                    ++start;
+                    break;
+                case internal::INCOMPLETE_SEQUENCE:
+                case internal::OVERLONG_SEQUENCE:
+                case internal::INVALID_CODE_POINT:
+                    out = utf8::append (replacement, out);
+                    ++start;
+                    // just one replacement mark for the sequence
+                    while (start != end && utf8::internal::is_trail(*start))
+                        ++start;
+                    break;
+            }
+        }
+        return out;
+    }
+
+    template <typename octet_iterator, typename output_iterator>
+    inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
+    {
+        static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
+        return utf8::replace_invalid(start, end, out, replacement_marker);
+    }
+
+    template <typename octet_iterator>
+    uint32_t next(octet_iterator& it, octet_iterator end)
+    {
+        uint32_t cp = 0;
+        internal::utf_error err_code = utf8::internal::validate_next(it, end, cp);
+        switch (err_code) {
+            case internal::UTF8_OK :
+                break;
+            case internal::NOT_ENOUGH_ROOM :
+                throw not_enough_room();
+            case internal::INVALID_LEAD :
+            case internal::INCOMPLETE_SEQUENCE :
+            case internal::OVERLONG_SEQUENCE :
+                throw invalid_utf8(static_cast<uint8_t>(*it));
+            case internal::INVALID_CODE_POINT :
+                throw invalid_code_point(cp);
+        }
+        return cp;
+    }
+
+    template <typename octet_iterator>
+    uint32_t peek_next(octet_iterator it, octet_iterator end)
+    {
+        return utf8::next(it, end);
+    }
+
+    template <typename octet_iterator>
+    uint32_t prior(octet_iterator& it, octet_iterator start)
+    {
+        // can't do much if it == start
+        if (it == start)
+            throw not_enough_room();
+
+        octet_iterator end = it;
+        // Go back until we hit either a lead octet or start
+        while (utf8::internal::is_trail(*(--it)))
+            if (it == start)
+                throw invalid_utf8(*it); // error - no lead byte in the sequence
+        return utf8::peek_next(it, end);
+    }
+
+    template <typename octet_iterator, typename distance_type>
+    void advance (octet_iterator& it, distance_type n, octet_iterator end)
+    {
+        const distance_type zero(0);
+        if (n < zero) {
+            // backward
+            for (distance_type i = n; i < zero; ++i)
+                utf8::prior(it, end);
+        } else {
+            // forward
+            for (distance_type i = zero; i < n; ++i)
+                utf8::next(it, end);
+        }
+    }
+
+    template <typename octet_iterator>
+    typename std::iterator_traits<octet_iterator>::difference_type
+    distance (octet_iterator first, octet_iterator last)
+    {
+        typename std::iterator_traits<octet_iterator>::difference_type dist;
+        for (dist = 0; first < last; ++dist)
+            utf8::next(first, last);
+        return dist;
+    }
+
+    template <typename u16bit_iterator, typename octet_iterator>
+    octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
+    {
+        while (start != end) {
+            uint32_t cp = utf8::internal::mask16(*start++);
+            // Take care of surrogate pairs first
+            if (utf8::internal::is_lead_surrogate(cp)) {
+                if (start != end) {
+                    uint32_t trail_surrogate = utf8::internal::mask16(*start++);
+                    if (utf8::internal::is_trail_surrogate(trail_surrogate))
+                        cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
+                    else
+                        throw invalid_utf16(static_cast<uint16_t>(trail_surrogate));
+                }
+                else
+                    throw invalid_utf16(static_cast<uint16_t>(cp));
+
+            }
+            // Lone trail surrogate
+            else if (utf8::internal::is_trail_surrogate(cp))
+                throw invalid_utf16(static_cast<uint16_t>(cp));
+
+            result = utf8::append(cp, result);
+        }
+        return result;
+    }
+
+    template <typename u16bit_iterator, typename octet_iterator>
+    u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
+    {
+        while (start < end) {
+            uint32_t cp = utf8::next(start, end);
+            if (cp > 0xffff) { //make a surrogate pair
+                *result++ = static_cast<uint16_t>((cp >> 10)   + internal::LEAD_OFFSET);
+                *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
+            }
+            else
+                *result++ = static_cast<uint16_t>(cp);
+        }
+        return result;
+    }
+
+    template <typename octet_iterator, typename u32bit_iterator>
+    octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
+    {
+        while (start != end)
+            result = utf8::append(*(start++), result);
+
+        return result;
+    }
+
+    template <typename octet_iterator, typename u32bit_iterator>
+    u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
+    {
+        while (start < end)
+            (*result++) = utf8::next(start, end);
+
+        return result;
+    }
+
+    // The iterator class
+    template <typename octet_iterator>
+    class iterator {
+      octet_iterator it;
+      octet_iterator range_start;
+      octet_iterator range_end;
+      public:
+      typedef uint32_t value_type;
+      typedef uint32_t* pointer;
+      typedef uint32_t& reference;
+      typedef std::ptrdiff_t difference_type;
+      typedef std::bidirectional_iterator_tag iterator_category;
+      iterator () {}
+      explicit iterator (const octet_iterator& octet_it,
+                         const octet_iterator& rangestart,
+                         const octet_iterator& rangeend) :
+               it(octet_it), range_start(rangestart), range_end(rangeend)
+      {
+          if (it < range_start || it > range_end)
+              throw std::out_of_range("Invalid utf-8 iterator position");
+      }
+      // the default "big three" are OK
+      octet_iterator base () const { return it; }
+      uint32_t operator * () const
+      {
+          octet_iterator temp = it;
+          return utf8::next(temp, range_end);
+      }
+      bool operator == (const iterator& rhs) const
+      {
+          if (range_start != rhs.range_start || range_end != rhs.range_end)
+              throw std::logic_error("Comparing utf-8 iterators defined with different ranges");
+          return (it == rhs.it);
+      }
+      bool operator != (const iterator& rhs) const
+      {
+          return !(operator == (rhs));
+      }
+      iterator& operator ++ ()
+      {
+          utf8::next(it, range_end);
+          return *this;
+      }
+      iterator operator ++ (int)
+      {
+          iterator temp = *this;
+          utf8::next(it, range_end);
+          return temp;
+      }
+      iterator& operator -- ()
+      {
+          utf8::prior(it, range_start);
+          return *this;
+      }
+      iterator operator -- (int)
+      {
+          iterator temp = *this;
+          utf8::prior(it, range_start);
+          return temp;
+      }
+    }; // class iterator
+
+} // namespace utf8
+
+#if UTF_CPP_CPLUSPLUS >= 201703L // C++ 17 or later
+#include "cpp17.h"
+#elif UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
+#include "cpp11.h"
+#endif // C++ 11 or later
+
+#endif //header guard
+
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8/core.h b/paddlenlp/ops/fast_transformer/src/demo/utf8/core.h
new file mode 100644
index 000000000000..34371ee31c8c
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8/core.h
@@ -0,0 +1,387 @@
+// 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_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+#define UTF8_FOR_CPP_CORE_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+
+#include <iterator>
+
+// Determine the C++ standard version.
+// If the user defines UTF_CPP_CPLUSPLUS, use that.
+// Otherwise, trust the unreliable predefined macro __cplusplus
+
+#if !defined UTF_CPP_CPLUSPLUS
+    #define UTF_CPP_CPLUSPLUS __cplusplus
+#endif
+
+#if UTF_CPP_CPLUSPLUS >= 201103L // C++ 11 or later
+    #define UTF_CPP_OVERRIDE override
+    #define UTF_CPP_NOEXCEPT noexcept
+#else // C++ 98/03
+    #define UTF_CPP_OVERRIDE
+    #define UTF_CPP_NOEXCEPT throw()
+#endif // C++ 11 or later
+
+
+namespace utf8
+{
+    // The typedefs for 8-bit, 16-bit and 32-bit unsigned integers
+    // You may need to change them to match your system.
+    // These typedefs have the same names as ones from cstdint, or boost/cstdint
+    typedef unsigned char   uint8_t;
+    typedef unsigned short  uint16_t;
+    typedef unsigned int    uint32_t;
+
+// Helper code - not intended to be directly called by the library users. May be changed at any time
+namespace internal
+{
+    // Unicode constants
+    // Leading (high) surrogates: 0xd800 - 0xdbff
+    // Trailing (low) surrogates: 0xdc00 - 0xdfff
+    const uint16_t LEAD_SURROGATE_MIN  = 0xd800u;
+    const uint16_t LEAD_SURROGATE_MAX  = 0xdbffu;
+    const uint16_t TRAIL_SURROGATE_MIN = 0xdc00u;
+    const uint16_t TRAIL_SURROGATE_MAX = 0xdfffu;
+    const uint16_t LEAD_OFFSET         = 0xd7c0u;       // LEAD_SURROGATE_MIN - (0x10000 >> 10)
+    const uint32_t SURROGATE_OFFSET    = 0xfca02400u;   // 0x10000u - (LEAD_SURROGATE_MIN << 10) - TRAIL_SURROGATE_MIN
+
+    // Maximum valid value for a Unicode code point
+    const uint32_t CODE_POINT_MAX      = 0x0010ffffu;
+
+    template<typename octet_type>
+    inline uint8_t mask8(octet_type oc)
+    {
+        return static_cast<uint8_t>(0xff & oc);
+    }
+    template<typename u16_type>
+    inline uint16_t mask16(u16_type oc)
+    {
+        return static_cast<uint16_t>(0xffff & oc);
+    }
+    template<typename octet_type>
+    inline bool is_trail(octet_type oc)
+    {
+        return ((utf8::internal::mask8(oc) >> 6) == 0x2);
+    }
+
+    template <typename u16>
+    inline bool is_lead_surrogate(u16 cp)
+    {
+        return (cp >= LEAD_SURROGATE_MIN && cp <= LEAD_SURROGATE_MAX);
+    }
+
+    template <typename u16>
+    inline bool is_trail_surrogate(u16 cp)
+    {
+        return (cp >= TRAIL_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
+    }
+
+    template <typename u16>
+    inline bool is_surrogate(u16 cp)
+    {
+        return (cp >= LEAD_SURROGATE_MIN && cp <= TRAIL_SURROGATE_MAX);
+    }
+
+    template <typename u32>
+    inline bool is_code_point_valid(u32 cp)
+    {
+        return (cp <= CODE_POINT_MAX && !utf8::internal::is_surrogate(cp));
+    }
+
+    template <typename octet_iterator>
+    inline typename std::iterator_traits<octet_iterator>::difference_type
+    sequence_length(octet_iterator lead_it)
+    {
+        uint8_t lead = utf8::internal::mask8(*lead_it);
+        if (lead < 0x80)
+            return 1;
+        else if ((lead >> 5) == 0x6)
+            return 2;
+        else if ((lead >> 4) == 0xe)
+            return 3;
+        else if ((lead >> 3) == 0x1e)
+            return 4;
+        else
+            return 0;
+    }
+
+    template <typename octet_difference_type>
+    inline bool is_overlong_sequence(uint32_t cp, octet_difference_type length)
+    {
+        if (cp < 0x80) {
+            if (length != 1) 
+                return true;
+        }
+        else if (cp < 0x800) {
+            if (length != 2) 
+                return true;
+        }
+        else if (cp < 0x10000) {
+            if (length != 3) 
+                return true;
+        }
+
+        return false;
+    }
+
+    enum utf_error {UTF8_OK, NOT_ENOUGH_ROOM, INVALID_LEAD, INCOMPLETE_SEQUENCE, OVERLONG_SEQUENCE, INVALID_CODE_POINT};
+
+    /// Helper for get_sequence_x
+    template <typename octet_iterator>
+    utf_error increase_safely(octet_iterator& it, octet_iterator end)
+    {
+        if (++it == end)
+            return NOT_ENOUGH_ROOM;
+
+        if (!utf8::internal::is_trail(*it))
+            return INCOMPLETE_SEQUENCE;
+
+        return UTF8_OK;
+    }
+
+    #define UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(IT, END) {utf_error ret = increase_safely(IT, END); if (ret != UTF8_OK) return ret;}    
+
+    /// get_sequence_x functions decode utf-8 sequences of the length x
+    template <typename octet_iterator>
+    utf_error get_sequence_1(octet_iterator& it, octet_iterator end, uint32_t& code_point)
+    {
+        if (it == end)
+            return NOT_ENOUGH_ROOM;
+
+        code_point = utf8::internal::mask8(*it);
+
+        return UTF8_OK;
+    }
+
+    template <typename octet_iterator>
+    utf_error get_sequence_2(octet_iterator& it, octet_iterator end, uint32_t& code_point)
+    {
+        if (it == end) 
+            return NOT_ENOUGH_ROOM;
+
+        code_point = utf8::internal::mask8(*it);
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point = ((code_point << 6) & 0x7ff) + ((*it) & 0x3f);
+
+        return UTF8_OK;
+    }
+
+    template <typename octet_iterator>
+    utf_error get_sequence_3(octet_iterator& it, octet_iterator end, uint32_t& code_point)
+    {
+        if (it == end)
+            return NOT_ENOUGH_ROOM;
+            
+        code_point = utf8::internal::mask8(*it);
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point = ((code_point << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point += (*it) & 0x3f;
+
+        return UTF8_OK;
+    }
+
+    template <typename octet_iterator>
+    utf_error get_sequence_4(octet_iterator& it, octet_iterator end, uint32_t& code_point)
+    {
+        if (it == end)
+           return NOT_ENOUGH_ROOM;
+
+        code_point = utf8::internal::mask8(*it);
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point = ((code_point << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point += (utf8::internal::mask8(*it) << 6) & 0xfff;
+
+        UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR(it, end)
+
+        code_point += (*it) & 0x3f;
+
+        return UTF8_OK;
+    }
+
+    #undef UTF8_CPP_INCREASE_AND_RETURN_ON_ERROR
+
+    template <typename octet_iterator>
+    utf_error validate_next(octet_iterator& it, octet_iterator end, uint32_t& code_point)
+    {
+        if (it == end)
+            return NOT_ENOUGH_ROOM;
+
+        // Save the original value of it so we can go back in case of failure
+        // Of course, it does not make much sense with i.e. stream iterators
+        octet_iterator original_it = it;
+
+        uint32_t cp = 0;
+        // Determine the sequence length based on the lead octet
+        typedef typename std::iterator_traits<octet_iterator>::difference_type octet_difference_type;
+        const octet_difference_type length = utf8::internal::sequence_length(it);
+
+        // Get trail octets and calculate the code point
+        utf_error err = UTF8_OK;
+        switch (length) {
+            case 0:
+                return INVALID_LEAD;
+            case 1:
+                err = utf8::internal::get_sequence_1(it, end, cp);
+                break;
+            case 2:
+                err = utf8::internal::get_sequence_2(it, end, cp);
+            break;
+            case 3:
+                err = utf8::internal::get_sequence_3(it, end, cp);
+            break;
+            case 4:
+                err = utf8::internal::get_sequence_4(it, end, cp);
+            break;
+        }
+
+        if (err == UTF8_OK) {
+            // Decoding succeeded. Now, security checks...
+            if (utf8::internal::is_code_point_valid(cp)) {
+                if (!utf8::internal::is_overlong_sequence(cp, length)){
+                    // Passed! Return here.
+                    code_point = cp;
+                    ++it;
+                    return UTF8_OK;
+                }
+                else
+                    err = OVERLONG_SEQUENCE;
+            }
+            else 
+                err = INVALID_CODE_POINT;
+        }
+
+        // Failure branch - restore the original value of the iterator
+        it = original_it;
+        return err;
+    }
+
+    template <typename octet_iterator>
+    inline utf_error validate_next(octet_iterator& it, octet_iterator end) {
+        uint32_t ignored;
+        return utf8::internal::validate_next(it, end, ignored);
+    }
+
+    // Internal implementation of both checked and unchecked append() function
+    // This function will be invoked by the overloads below, as they will know
+    // the octet_type.
+    template <typename octet_iterator, typename octet_type>
+    octet_iterator append(uint32_t cp, octet_iterator result) {
+        if (cp < 0x80)                        // one octet
+            *(result++) = static_cast<octet_type>(cp);
+        else if (cp < 0x800) {                // two octets
+            *(result++) = static_cast<octet_type>((cp >> 6)          | 0xc0);
+            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);
+        }
+        else if (cp < 0x10000) {              // three octets
+            *(result++) = static_cast<octet_type>((cp >> 12)         | 0xe0);
+            *(result++) = static_cast<octet_type>(((cp >> 6) & 0x3f) | 0x80);
+            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);
+        }
+        else {                                // four octets
+            *(result++) = static_cast<octet_type>((cp >> 18)         | 0xf0);
+            *(result++) = static_cast<octet_type>(((cp >> 12) & 0x3f)| 0x80);
+            *(result++) = static_cast<octet_type>(((cp >> 6) & 0x3f) | 0x80);
+            *(result++) = static_cast<octet_type>((cp & 0x3f)        | 0x80);
+        }
+        return result;
+    }
+    
+    // One of the following overloads will be invoked from the API calls
+
+    // A simple (but dangerous) case: the caller appends byte(s) to a char array
+    inline char* append(uint32_t cp, char* result) {
+        return append<char*, char>(cp, result);
+    }
+
+    // Hopefully, most common case: the caller uses back_inserter
+    // i.e. append(cp, std::back_inserter(str));
+    template<typename container_type>
+    std::back_insert_iterator<container_type> append
+            (uint32_t cp, std::back_insert_iterator<container_type> result) {
+        return append<std::back_insert_iterator<container_type>,
+            typename container_type::value_type>(cp, result);
+    }
+
+    // The caller uses some other kind of output operator - not covered above
+    // Note that in this case we are not able to determine octet_type
+    // so we assume it's uint_8; that can cause a conversion warning if we are wrong.
+    template <typename octet_iterator>
+    octet_iterator append(uint32_t cp, octet_iterator result) {
+        return append<octet_iterator, uint8_t>(cp, result);
+    }
+
+} // namespace internal
+
+    /// The library API - functions intended to be called by the users
+
+    // Byte order mark
+    const uint8_t bom[] = {0xef, 0xbb, 0xbf};
+
+    template <typename octet_iterator>
+    octet_iterator find_invalid(octet_iterator start, octet_iterator end)
+    {
+        octet_iterator result = start;
+        while (result != end) {
+            utf8::internal::utf_error err_code = utf8::internal::validate_next(result, end);
+            if (err_code != internal::UTF8_OK)
+                return result;
+        }
+        return result;
+    }
+
+    template <typename octet_iterator>
+    inline bool is_valid(octet_iterator start, octet_iterator end)
+    {
+        return (utf8::find_invalid(start, end) == end);
+    }
+
+    template <typename octet_iterator>
+    inline bool starts_with_bom (octet_iterator it, octet_iterator end)
+    {
+        return (
+            ((it != end) && (utf8::internal::mask8(*it++)) == bom[0]) &&
+            ((it != end) && (utf8::internal::mask8(*it++)) == bom[1]) &&
+            ((it != end) && (utf8::internal::mask8(*it))   == bom[2])
+           );
+    }	
+} // namespace utf8
+
+#endif // header guard
+
+
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp11.h b/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp11.h
new file mode 100644
index 000000000000..2366f12915cb
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp11.h
@@ -0,0 +1,103 @@
+// Copyright 2018 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_a184c22c_d012_11e8_a8d5_f2801f1b9fd1
+#define UTF8_FOR_CPP_a184c22c_d012_11e8_a8d5_f2801f1b9fd1
+
+#include "checked.h"
+#include <string>
+
+namespace utf8
+{
+
+    inline void append(char32_t cp, std::string& s)
+    {
+        append(uint32_t(cp), std::back_inserter(s));
+    }
+
+    inline std::string utf16to8(const std::u16string& s)
+    {
+        std::string result;
+        utf16to8(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::u16string utf8to16(const std::string& s)
+    {
+        std::u16string result;
+        utf8to16(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::string utf32to8(const std::u32string& s)
+    {
+        std::string result;
+        utf32to8(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::u32string utf8to32(const std::string& s)
+    {
+        std::u32string result;
+        utf8to32(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::size_t find_invalid(const std::string& s)
+    {
+        std::string::const_iterator invalid = find_invalid(s.begin(), s.end());
+        return (invalid == s.end()) ? std::string::npos : static_cast<std::size_t>(invalid - s.begin());
+    }
+
+    inline bool is_valid(const std::string& s)
+    {
+        return is_valid(s.begin(), s.end());
+    }
+
+    inline std::string replace_invalid(const std::string& s, char32_t replacement)
+    {
+        std::string result;
+        replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);
+        return result;
+    }
+
+    inline std::string replace_invalid(const std::string& s)
+    {
+        std::string result;
+        replace_invalid(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline bool starts_with_bom(const std::string& s)
+    {
+        return starts_with_bom(s.begin(), s.end());
+    }
+ 
+} // namespace utf8
+
+#endif // header guard
+
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp17.h b/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp17.h
new file mode 100644
index 000000000000..32a77ce30750
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8/cpp17.h
@@ -0,0 +1,103 @@
+// Copyright 2018 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_7e906c01_03a3_4daf_b420_ea7ea952b3c9
+#define UTF8_FOR_CPP_7e906c01_03a3_4daf_b420_ea7ea952b3c9
+
+#include "checked.h"
+#include <string>
+
+namespace utf8
+{
+
+    inline void append(char32_t cp, std::string& s)
+    {
+        append(uint32_t(cp), std::back_inserter(s));
+    }
+
+    inline std::string utf16to8(std::u16string_view s)
+    {
+        std::string result;
+        utf16to8(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::u16string utf8to16(std::string_view s)
+    {
+        std::u16string result;
+        utf8to16(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::string utf32to8(std::u32string_view s)
+    {
+        std::string result;
+        utf32to8(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::u32string utf8to32(std::string_view s)
+    {
+        std::u32string result;
+        utf8to32(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline std::size_t find_invalid(std::string_view s)
+    {
+        std::string_view::const_iterator invalid = find_invalid(s.begin(), s.end());
+        return (invalid == s.end()) ? std::string_view::npos : static_cast<std::size_t>(invalid - s.begin());
+    }
+
+    inline bool is_valid(std::string_view s)
+    {
+        return is_valid(s.begin(), s.end());
+    }
+
+    inline std::string replace_invalid(std::string_view s, char32_t replacement)
+    {
+        std::string result;
+        replace_invalid(s.begin(), s.end(), std::back_inserter(result), replacement);
+        return result;
+    }
+
+    inline std::string replace_invalid(std::string_view s)
+    {
+        std::string result;
+        replace_invalid(s.begin(), s.end(), std::back_inserter(result));
+        return result;
+    }
+
+    inline bool starts_with_bom(std::string_view s)
+    {
+        return starts_with_bom(s.begin(), s.end());
+    }
+ 
+} // namespace utf8
+
+#endif // header guard
+
diff --git a/paddlenlp/ops/fast_transformer/src/demo/utf8/unchecked.h b/paddlenlp/ops/fast_transformer/src/demo/utf8/unchecked.h
new file mode 100644
index 000000000000..8fe83c9ecbc7
--- /dev/null
+++ b/paddlenlp/ops/fast_transformer/src/demo/utf8/unchecked.h
@@ -0,0 +1,257 @@
+// 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_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+#define UTF8_FOR_CPP_UNCHECKED_H_2675DCD0_9480_4c0c_B92A_CC14C027B731
+
+#include "core.h"
+
+namespace utf8
+{
+    namespace unchecked
+    {
+        template <typename octet_iterator>
+        octet_iterator append(uint32_t cp, octet_iterator result)
+        {
+            return internal::append(cp, result);
+        }
+
+        template <typename octet_iterator, typename output_iterator>
+        output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out, uint32_t replacement)
+        {
+            while (start != end) {
+                octet_iterator sequence_start = start;
+                internal::utf_error err_code = utf8::internal::validate_next(start, end);
+                switch (err_code) {
+                    case internal::UTF8_OK :
+                        for (octet_iterator it = sequence_start; it != start; ++it)
+                            *out++ = *it;
+                        break;
+                    case internal::NOT_ENOUGH_ROOM:
+                        out = utf8::unchecked::append (replacement, out);
+                        start = end;
+                        break;
+                    case internal::INVALID_LEAD:
+                        out = utf8::unchecked::append (replacement, out);
+                        ++start;
+                        break;
+                    case internal::INCOMPLETE_SEQUENCE:
+                    case internal::OVERLONG_SEQUENCE:
+                    case internal::INVALID_CODE_POINT:
+                        out = utf8::unchecked::append (replacement, out);
+                        ++start;
+                        // just one replacement mark for the sequence
+                        while (start != end && utf8::internal::is_trail(*start))
+                            ++start;
+                        break;
+                }
+            }
+            return out;
+        }
+
+        template <typename octet_iterator, typename output_iterator>
+        inline output_iterator replace_invalid(octet_iterator start, octet_iterator end, output_iterator out)
+        {
+            static const uint32_t replacement_marker = utf8::internal::mask16(0xfffd);
+            return utf8::unchecked::replace_invalid(start, end, out, replacement_marker);
+        }
+
+        template <typename octet_iterator>
+        uint32_t next(octet_iterator& it)
+        {
+            uint32_t cp = utf8::internal::mask8(*it);
+            typename std::iterator_traits<octet_iterator>::difference_type length = utf8::internal::sequence_length(it);
+            switch (length) {
+                case 1:
+                    break;
+                case 2:
+                    it++;
+                    cp = ((cp << 6) & 0x7ff) + ((*it) & 0x3f);
+                    break;
+                case 3:
+                    ++it; 
+                    cp = ((cp << 12) & 0xffff) + ((utf8::internal::mask8(*it) << 6) & 0xfff);
+                    ++it;
+                    cp += (*it) & 0x3f;
+                    break;
+                case 4:
+                    ++it;
+                    cp = ((cp << 18) & 0x1fffff) + ((utf8::internal::mask8(*it) << 12) & 0x3ffff);                
+                    ++it;
+                    cp += (utf8::internal::mask8(*it) << 6) & 0xfff;
+                    ++it;
+                    cp += (*it) & 0x3f; 
+                    break;
+            }
+            ++it;
+            return cp;
+        }
+
+        template <typename octet_iterator>
+        uint32_t peek_next(octet_iterator it)
+        {
+            return utf8::unchecked::next(it);
+        }
+
+        template <typename octet_iterator>
+        uint32_t prior(octet_iterator& it)
+        {
+            while (utf8::internal::is_trail(*(--it))) ;
+            octet_iterator temp = it;
+            return utf8::unchecked::next(temp);
+        }
+
+        template <typename octet_iterator, typename distance_type>
+        void advance (octet_iterator& it, distance_type n)
+        {
+            const distance_type zero(0);
+            if (n < zero) {
+                // backward
+                for (distance_type i = n; i < zero; ++i)
+                    utf8::unchecked::prior(it);
+            } else {
+                // forward
+                for (distance_type i = zero; i < n; ++i)
+                    utf8::unchecked::next(it);
+            }
+        }
+
+        template <typename octet_iterator>
+        typename std::iterator_traits<octet_iterator>::difference_type
+        distance (octet_iterator first, octet_iterator last)
+        {
+            typename std::iterator_traits<octet_iterator>::difference_type dist;
+            for (dist = 0; first < last; ++dist) 
+                utf8::unchecked::next(first);
+            return dist;
+        }
+
+        template <typename u16bit_iterator, typename octet_iterator>
+        octet_iterator utf16to8 (u16bit_iterator start, u16bit_iterator end, octet_iterator result)
+        {
+            while (start != end) {
+                uint32_t cp = utf8::internal::mask16(*start++);
+            // Take care of surrogate pairs first
+                if (utf8::internal::is_lead_surrogate(cp)) {
+                    uint32_t trail_surrogate = utf8::internal::mask16(*start++);
+                    cp = (cp << 10) + trail_surrogate + internal::SURROGATE_OFFSET;
+                }
+                result = utf8::unchecked::append(cp, result);
+            }
+            return result;
+        }
+
+        template <typename u16bit_iterator, typename octet_iterator>
+        u16bit_iterator utf8to16 (octet_iterator start, octet_iterator end, u16bit_iterator result)
+        {
+            while (start < end) {
+                uint32_t cp = utf8::unchecked::next(start);
+                if (cp > 0xffff) { //make a surrogate pair
+                    *result++ = static_cast<uint16_t>((cp >> 10)   + internal::LEAD_OFFSET);
+                    *result++ = static_cast<uint16_t>((cp & 0x3ff) + internal::TRAIL_SURROGATE_MIN);
+                }
+                else
+                    *result++ = static_cast<uint16_t>(cp);
+            }
+            return result;
+        }
+
+        template <typename octet_iterator, typename u32bit_iterator>
+        octet_iterator utf32to8 (u32bit_iterator start, u32bit_iterator end, octet_iterator result)
+        {
+            while (start != end)
+                result = utf8::unchecked::append(*(start++), result);
+
+            return result;
+        }
+
+        template <typename octet_iterator, typename u32bit_iterator>
+        u32bit_iterator utf8to32 (octet_iterator start, octet_iterator end, u32bit_iterator result)
+        {
+            while (start < end)
+                (*result++) = utf8::unchecked::next(start);
+
+            return result;
+        }
+
+        // The iterator class
+        template <typename octet_iterator>
+          class iterator {
+            octet_iterator it;
+            public:
+            typedef uint32_t value_type;
+            typedef uint32_t* pointer;
+            typedef uint32_t& reference;
+            typedef std::ptrdiff_t difference_type;
+            typedef std::bidirectional_iterator_tag iterator_category;
+            iterator () {}
+            explicit iterator (const octet_iterator& octet_it): it(octet_it) {}
+            // the default "big three" are OK
+            octet_iterator base () const { return it; }
+            uint32_t operator * () const
+            {
+                octet_iterator temp = it;
+                return utf8::unchecked::next(temp);
+            }
+            bool operator == (const iterator& rhs) const 
+            { 
+                return (it == rhs.it);
+            }
+            bool operator != (const iterator& rhs) const
+            {
+                return !(operator == (rhs));
+            }
+            iterator& operator ++ () 
+            {
+                ::std::advance(it, utf8::internal::sequence_length(it));
+                return *this;
+            }
+            iterator operator ++ (int)
+            {
+                iterator temp = *this;
+                ::std::advance(it, utf8::internal::sequence_length(it));
+                return temp;
+            }  
+            iterator& operator -- ()
+            {
+                utf8::unchecked::prior(it);
+                return *this;
+            }
+            iterator operator -- (int)
+            {
+                iterator temp = *this;
+                utf8::unchecked::prior(it);
+                return temp;
+            }
+          }; // class iterator
+
+    } // namespace utf8::unchecked
+} // namespace utf8 
+
+
+#endif // header guard
+
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_bart_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_bart_decoding_op.h
index 9ae62bd49cf8..f1480b861856 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_bart_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_bart_decoding_op.h
@@ -22,7 +22,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_decoder_op.h b/paddlenlp/ops/fast_transformer/src/fusion_decoder_op.h
index 0b1f61f8e5a5..ec4e2966b60a 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_decoder_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_decoder_op.h
@@ -20,7 +20,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_decoding_op.h
index 2a799e3314dd..c6e476302086 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_decoding_op.h
@@ -24,7 +24,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.cu b/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.cu
index 425c89e941db..2fe897147ef8 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.cu
+++ b/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.cu
@@ -91,7 +91,7 @@ std::vector<paddle::Tensor> encoder_kernel(
 
   if (normalize_before == false) {
     typedef BertEncoderTransformerTraits<traits_::OpType,
-                                        cuda::OpenMultiHeadAttention>
+                                        fastertransformer::cuda::OpenMultiHeadAttention>
         EncoderTraits_;
 
     // Post-Normalization
@@ -202,7 +202,7 @@ std::vector<paddle::Tensor> encoder_kernel(
     delete allocator_;
     delete encoder;
   } else {
-    typedef OpenEncoderTraits<traits_::OpType, cuda::OpenMultiHeadAttention>
+    typedef OpenEncoderTraits<traits_::OpType, fastertransformer::cuda::OpenMultiHeadAttention>
         OpenEncoderTraits_;
 
     // Pre-Normalization
@@ -440,4 +440,4 @@ std::vector<paddle::Tensor> EncoderCUDAForward(
     }
   }
   return ret;
-}
\ No newline at end of file
+}
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.h b/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.h
index 84631eb17c0d..fd6daa2f0d4a 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_encoder_op.h
@@ -20,7 +20,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
@@ -58,4 +60,4 @@ std::vector<paddle::Tensor> EncoderCUDAForward(
     int64_t layer_idx_,
     bool allow_gemm_test,
     bool use_trt_kernel_,
-    bool normalize_before);
\ No newline at end of file
+    bool normalize_before);
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_force_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_force_decoding_op.h
index 9cd11c7d0f22..973329c17b69 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_force_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_force_decoding_op.h
@@ -24,7 +24,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_gpt_op.h b/paddlenlp/ops/fast_transformer/src/fusion_gpt_op.h
index 7fc21fac69b7..39b73b89809a 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_gpt_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_gpt_op.h
@@ -22,7 +22,9 @@
 // #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_gptj_op.h b/paddlenlp/ops/fast_transformer/src/fusion_gptj_op.h
index 0470de164433..c41d645fda76 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_gptj_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_gptj_op.h
@@ -22,7 +22,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_mbart_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_mbart_decoding_op.h
index b8144709432b..159d4e9070ee 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_mbart_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_mbart_decoding_op.h
@@ -22,7 +22,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_miro_op.h b/paddlenlp/ops/fast_transformer/src/fusion_miro_op.h
index 00f0ab4049c2..081fef05010d 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_miro_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_miro_op.h
@@ -24,7 +24,9 @@ limitations under the License. */
 #include "utils.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_opt_op.h b/paddlenlp/ops/fast_transformer/src/fusion_opt_op.h
index 619af39920f3..b87ccdc46885 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_opt_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_opt_op.h
@@ -22,7 +22,9 @@
 // #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_pegasus_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_pegasus_decoding_op.h
index 54ecd92d0c64..5a4e2962cd74 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_pegasus_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_pegasus_decoding_op.h
@@ -22,7 +22,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_t5_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_t5_decoding_op.h
index 95557a07832f..15750959fed1 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_t5_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_t5_decoding_op.h
@@ -23,7 +23,9 @@ limitations under the License. */
 #include "fastertransformer/utils/common.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/src/fusion_unified_decoding_op.h b/paddlenlp/ops/fast_transformer/src/fusion_unified_decoding_op.h
index 8f8b54c06d0e..6ca034f3c79c 100644
--- a/paddlenlp/ops/fast_transformer/src/fusion_unified_decoding_op.h
+++ b/paddlenlp/ops/fast_transformer/src/fusion_unified_decoding_op.h
@@ -24,7 +24,9 @@ limitations under the License. */
 #include "utils.h"
 
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/fast_transformer/transformer/encoder.py b/paddlenlp/ops/fast_transformer/transformer/encoder.py
index 4394401e916e..da14723dbb54 100644
--- a/paddlenlp/ops/fast_transformer/transformer/encoder.py
+++ b/paddlenlp/ops/fast_transformer/transformer/encoder.py
@@ -300,7 +300,7 @@ def encoder_forward(self, src, src_mask=None, cache=None):
             self.ffn_out_weight.append(layer.linear2.weight)
             self.ffn_out_bias.append(layer.linear2.bias)
 
-    (output,) = infer_transformer_encoder(
+    output = infer_transformer_encoder(
         input=[src],
         attn_mask=[src_mask],
         q_weight=self.q_weight,
diff --git a/paddlenlp/ops/patches/FasterTransformer/CMakeLists.txt b/paddlenlp/ops/patches/FasterTransformer/CMakeLists.txt
index 52b3c0476377..9e4e460d265a 100644
--- a/paddlenlp/ops/patches/FasterTransformer/CMakeLists.txt
+++ b/paddlenlp/ops/patches/FasterTransformer/CMakeLists.txt
@@ -43,7 +43,7 @@ if(BUILD_GPT)
   set(CMAKE_MODULE_PATH "") # prevent the bugs for pytorch building
 endif()
 
-set(CXX_STD "14" CACHE STRING "C++ standard")
+set(CXX_STD "17" CACHE STRING "C++ standard")
 
 set(CUDA_PATH ${CUDA_TOOLKIT_ROOT_DIR})
 
@@ -142,8 +142,8 @@ set(CMAKE_CXX_FLAGS_DEBUG  "${CMAKE_CXX_FLAGS_DEBUG}  -Wall -O0")
 # set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CUDA_FLAGS_DEBUG} -O0 -G -Xcompiler -Wall  --ptxas-options=-v --resource-usage")
 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}")
@@ -203,7 +203,7 @@ if(BUILD_PD)
       message(FATAL_ERROR "please set PADDLE_LIB with -DPADDLE_LIB=/path/paddle/lib")
     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")
@@ -227,7 +227,7 @@ if(BUILD_PD)
     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}")
 
     if (USE_TENSORRT AND WITH_GPU)
       set(TENSORRT_ROOT "" CACHE STRING "The root directory of TensorRT library")
diff --git a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/cuda/masked_multihead_attention.cu b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/cuda/masked_multihead_attention.cu
index d750e361b6d9..310b6daeb78b 100644
--- a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/cuda/masked_multihead_attention.cu
+++ b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/cuda/masked_multihead_attention.cu
@@ -19,7 +19,7 @@
 #include "masked_multihead_attention_utils.h"
 #include <assert.h>
 #include <float.h>
-
+#include <stdexcept>
 //#define MMHA_USE_HMMA_FOR_REDUCTION
 
 // Below are knobs to extend FP32 accumulation for higher FP16 accuracy
diff --git a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/allocator.h b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/allocator.h
index 8a399cf37fd6..074ab2880919 100644
--- a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/allocator.h
+++ b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/allocator.h
@@ -27,7 +27,9 @@
 
 #ifdef PADDLE_CUDA
 #ifdef PADDLE_ON_INFERENCE
-#include "paddle/include/experimental/ext_all.h"
+#include "paddle/extension.h"
+#include "paddle_inference_api.h"
+#include "paddle/phi/api/ext/exception.h"
 #else
 #include "paddle/extension.h"
 #endif
diff --git a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/common.h b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/common.h
index 9aa3fef63f4c..dc748dc50529 100644
--- a/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/common.h
+++ b/paddlenlp/ops/patches/FasterTransformer/fastertransformer/utils/common.h
@@ -23,6 +23,7 @@
 #include <fstream>
 #include <iostream>
 #include <map>
+#include <string>
 #include <stdexcept>
 #include "stdio.h"
 
diff --git a/paddlenlp/transformers/gpt/modeling.py b/paddlenlp/transformers/gpt/modeling.py
index 10bdb11e3c65..d6363db446a7 100644
--- a/paddlenlp/transformers/gpt/modeling.py
+++ b/paddlenlp/transformers/gpt/modeling.py
@@ -969,7 +969,7 @@ def forward(
             loss_mask = loss_mask.reshape([-1])
             masked_lm_loss = paddle.sum(masked_lm_loss.reshape([-1]) * loss_mask)
             loss = masked_lm_loss / loss_mask.sum()
-            return loss
+            return loss, logits
 
 
 class GPTPretrainingCriterion(paddle.nn.Layer):
diff --git a/scripts/regression/ci_case.sh b/scripts/regression/ci_case.sh
index 548400f4a6ed..14d6931d0c06 100644
--- a/scripts/regression/ci_case.sh
+++ b/scripts/regression/ci_case.sh
@@ -17,6 +17,11 @@ export nlp_dir=${PWD}
 export log_path=${nlp_dir}/model_logs
 export cudaid1=$2
 export cudaid2=$3
+export C_COMPILER_PATH=$(which gcc)
+export CXX_COMPILER_PATH=$(which g++)
+export CC=$(which gcc)
+export CXX=$(which g++)
+
 if [ ! -d "model_logs" ];then
     mkdir model_logs
 fi
@@ -238,17 +243,20 @@ cd ${nlp_dir}/paddlenlp/ops
 #python
 mkdir build_gpt_so
 cd build_gpt_so/
-cmake ..  -DCMAKE_BUILD_TYPE=Release -DPY_CMD=python -DWITH_GPT=ON -DPADDLE_LIB=${nlp_dir}/paddle_inference/ -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/gpt.cc \
- -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON  -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON -DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python \
- -DPYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.8.0/lib -DPYTHON_LIBRARY=/opt/_internal/cpython-3.8.0/include/python3.8 
+cmake ..  -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${C_COMPILER_PATH} -DCMAKE_CXX_COMPILER=${CXX_COMPILER_PATH} \
+-DPADDLE_LIB=${nlp_dir}/paddle_inference/ -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/gpt.cc \
+-DPY_CMD=python -DWITH_GPT=ON -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON \
+-DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python -DPYTHON_INCLUDE_DIRS=/opt/_internal/cpython-3.8.0/include/python3.8 -DPYTHON_LIBRARIES=/opt/_internal/cpython-3.8.0/lib
 make -j >${log_path}/GPT_python_FT >>${log_path}/gpt_python_FT 2>&1
 print_info $? gpt_python_FT
 cd ../
 #c++
 mkdir build_gpt_cc
 cd build_gpt_cc/
-cmake ..  -DWITH_GPT=ON -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=${nlp_dir}/paddle_inference/ -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/gpt.cc \
- -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON -DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python -DPYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.8.0/lib -DPYTHON_LIBRARY=/opt/_internal/cpython-3.8.0/include/python3.8 
+cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=${C_COMPILER_PATH} -DCMAKE_CXX_COMPILER=${CXX_COMPILER_PATH} \
+-DPADDLE_LIB=${nlp_dir}/paddle_inference/ -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/gpt.cc \
+-DWITH_GPT=ON -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON \
+-DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python -DPYTHON_INCLUDE_DIRS=/opt/_internal/cpython-3.8.0/include/python3.8 -DPYTHON_LIBRARIES=/opt/_internal/cpython-3.8.0/lib
 make -j >${log_path}/GPT_C_FT >>${log_path}/gpt_C_FT 2>&1
 print_info $? gpt_C_FT
 #depoly python
@@ -334,7 +342,7 @@ print_info $? gpt_p_depoly
 # python -m pytest ./tests/model_zoo/test_gpt.py >${log_path}/gpt >>${log_path}/gpt 2>&1
 # print_info $? gpt
 
-# fast_gpt
+fast_gpt
 cd ${nlp_dir}/fast_generation/samples
 python gpt_sample.py >${log_path}/fast_generation_gpt >>${log_path}/fast_generation_gpt 2>&1
 print_info $? fast_generation_gpt
@@ -343,7 +351,8 @@ print_info $? fast_generation_gpt
 ernie(){
 #data process
 cd ${nlp_dir}/model_zoo/ernie-1.0/
-mkdir data && cd data
+mkdir data
+cd ./data
 wget -q https://paddlenlp.bj.bcebos.com/models/transformers/data_tools/ernie_wudao_0903_92M_ids.npy
 wget -q https://paddlenlp.bj.bcebos.com/models/transformers/data_tools/ernie_wudao_0903_92M_idx.npz
 cd ../
@@ -696,15 +705,27 @@ cd ${nlp_dir}/paddlenlp/ops
 #python op
 mkdir build_tr_so
 cd build_tr_so/
-cmake ..  -DCMAKE_BUILD_TYPE=Release -DPY_CMD=python -DPADDLE_LIB=${nlp_dir}/paddle_inference -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/transformer_e2e.cc \
- -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON -DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python -DPYTHON_INCLUDE_DIR=/opt/_internal/cpython-3.8.0/lib -DPYTHON_LIBRARY=/opt/_internal/cpython-3.8.0/include/python3.8 
+cmake ..  -DCMAKE_BUILD_TYPE=Release \
+-DCMAKE_C_COMPILER=${C_COMPILER_PATH} \
+-DCMAKE_CXX_COMPILER=${CXX_COMPILER_PATH} \
+-DPY_CMD=python \
+-DPADDLE_LIB=${nlp_dir}/paddle_inference \
+-DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/transformer_e2e.cc \
+-DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON \
+-DPYTHON_EXECUTABLE=/opt/_internal/cpython-3.8.0/bin/python \
+-DPYTHON_INCLUDE_DIRS=/opt/_internal/cpython-3.8.0/include/python3.8 \
+-DPYTHON_LIBRARIES=/opt/_internal/cpython-3.8.0/lib
 make -j >${log_path}/transformer_python_FT >>${log_path}/transformer_python_FT 2>&1
 print_info $? transformer_python_FT
 cd ../
 #C++ op
 mkdir build_tr_cc
 cd build_tr_cc/
-cmake .. -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=${nlp_dir}/paddle_inference -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/transformer_e2e.cc -DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON
+cmake .. -DCMAKE_BUILD_TYPE=Release \
+-DCMAKE_C_COMPILER=${C_COMPILER_PATH} \
+-DCMAKE_CXX_COMPILER=${CXX_COMPILER_PATH} \
+-DPADDLE_LIB=${nlp_dir}/paddle_inference -DDEMO=${nlp_dir}/paddlenlp/ops/fast_transformer/src/demo/transformer_e2e.cc \
+-DON_INFER=ON -DWITH_MKL=ON -DWITH_ONNXRUNTIME=ON
 make -j >${log_path}/transformer_C_FT >>${log_path}/transformer_C_FT 2>&1
 print_info $? transformer_C_FT
 #deploy python
@@ -1075,10 +1096,6 @@ for apicase in `ls`;do
 done
 }
 fast_generation(){
-
-export CC=/usr/local/gcc-8.2/bin/gcc
-export CXX=/usr/local/gcc-8.2/bin/g++
-
 cd ${nlp_dir}/fast_generation/samples
 python codegen_sample.py >${log_path}/fast_generation_codegen >>${log_path}/fast_generation_codegen 2>&1
 print_info $? fast_generation_codegen


Code review comments:
diff_hunk: @@ -198,9 +201,17 @@ def build_with_command(self, ext_builder):
         # `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()
+
+        self.cmake_args += ["-DCMAKE_C_COMPILER={}".format(os.getenv("C_COMPILER_PATH"))]
+        self.cmake_args += ["-DCMAKE_CXX_COMPILER={}".format(os.getenv("CXX_COMPILER_PATH"))]
+
+        self.cmake_args += ["-DPYTHON_LIBRARY={}".format(distutils.sysconfig.get_config_var("LIBDIR"))]
+        self.cmake_args += ["-DPYTHON_INCLUDE_DIR={}".format(distutils.sysconfig.get_python_inc())]
path: paddlenlp/ops/ext_utils.py
text: @user1:
是否可以直接使用sysconfig的一些方法拿到了，distutils之前因为deprecated有想要去掉

```python
# 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
```

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

diff_hunk: @@ -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}
path: paddlenlp/ops/CMakeLists.txt
text: @user1:
这里的`CMAKE_CXX_COMPILER`是否要明确写死这个路径了

@author:
已经修改，通过环境变量设置gcc和g++