[Pytorch --- 7] RuntimeError: cublas runtime error : library not initialized at THCGeneral.cpp:228

    技术2022-07-10  159

    1. 背景

    在调试Roberta模型时,输入input_ids和attention mask后,出现报错:

    RuntimeError: cublas runtime error : library not initialized at /opt/conda/conda-bld/pytorch-nightly_1553749783957/work/aten/src/THC/THCGeneral.cpp:228

    2. 原因

    在这个报错之下出现了新的报错

    /opt/conda/conda-bld/pytorch-nightly_1553749783957/work/aten/src/THCUNN/ClassNLLCriterion.cu:105: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [0,0,0] Assertion `t >= 0 && t < n_classes` failed.

    熟悉Pytorch的同学一看就知道,这个报错是由于在分类任务中,计算CrossEntropyLoss时,ground_truth中的label数大于logits中的label数。

    3. 解决方案

    调整分类任务Linear的输出维度,即可修复这个bug

    Processed: 0.015, SQL: 9