[BugFix][Optimization] Replace silent failures with catchable exceptions and informative error messages (#6533)

* init

* init

* fix format

* add

* add files

* add ut

* fix some

* add ut

* add more

* add

* fix pre-commit

* fix pre-commit

* fix cover

* skip long seq

* add

* add

* fix

* remove not need

* fix set attr

* fix comments

* fix comments

* fix failed tests

---------

Co-authored-by: gongweibao <gognweibao@baidu.com>
This commit is contained in:
gongweibao
2026-03-16 21:32:43 +08:00
committed by GitHub
parent d113397b09
commit a6351dea0b
61 changed files with 1595 additions and 171 deletions
+13 -12
View File
@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include "cuda_multiprocess.h"
#include "helper.h"
#include "paddle/extension.h"
@@ -47,24 +48,24 @@ void SwapCacheImpl(const paddle::Tensor& cache_gpu, // gpu
auto* cache_gpu_ptr_now = cache_gpu_ptr + gpu_block_id * cache_stride;
auto* cache_cpu_ptr_now = cache_cpu_ptr + cpu_block_id * cache_stride;
if (mode == 0) { // copy from device to host
cudaMemcpyAsync(cache_cpu_ptr_now,
cache_gpu_ptr_now,
cache_stride * sizeof(DataType_),
cudaMemcpyDeviceToHost,
stream);
checkCudaErrors(cudaMemcpyAsync(cache_cpu_ptr_now,
cache_gpu_ptr_now,
cache_stride * sizeof(DataType_),
cudaMemcpyDeviceToHost,
stream));
// cudaMemcpy(cache_dst_ptr_now, cache_src_ptr_now, cache_stride *
// sizeof(DataType_), cudaMemcpyDeviceToHost);
} else { // copy from host to device
cudaMemcpyAsync(cache_gpu_ptr_now,
cache_cpu_ptr_now,
cache_stride * sizeof(DataType_),
cudaMemcpyHostToDevice,
stream);
checkCudaErrors(cudaMemcpyAsync(cache_gpu_ptr_now,
cache_cpu_ptr_now,
cache_stride * sizeof(DataType_),
cudaMemcpyHostToDevice,
stream));
// cudaMemcpy(cache_dst_ptr_now, cache_src_ptr_now, cache_stride *
// sizeof(DataType_), cudaMemcpyHostToDevice);
}
}
cudaStreamSynchronize(stream);
checkCudaErrors(cudaStreamSynchronize(stream));
}
void SwapCache(const paddle::Tensor& cache_gpu, // gpu
@@ -74,7 +75,7 @@ void SwapCache(const paddle::Tensor& cache_gpu, // gpu
const std::vector<int64_t>& swap_block_ids_cpu,
int rank,
int mode) {
cudaSetDevice(rank); // used for distributed launch
checkCudaErrors(cudaSetDevice(rank)); // used for distributed launch
switch (cache_gpu.dtype()) {
case paddle::DataType::BFLOAT16:
return SwapCacheImpl<paddle::DataType::BFLOAT16>(cache_gpu,