微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python:PyCUDA 错误:模块清理时上下文堆栈不为空

如何解决Python:PyCUDA 错误:模块清理时上下文堆栈不为空

我创建了一个 Streamlit 应用程序,作为在 PyTorch 中使用 mBERT 进行多语言文本分类项目的演示。当我使用命令 python app.py 运行应用程序时,它工作正常,但是当我尝试将 Streamlit 与命令 streamlit run app.py 一起使用时,它会引发 PyCUDA 错误

以下是 app.py 中的代码

import torch

from typing import Text
import streamlit as st
import pandas as pd
from textblob import TextBlob

from inference.inference_onnx import run_onnx_inference
from inference.inference_tensorRT import run_trt_inference
from googletrans import Translator

st.title("LinClass: Multilingual Text Classifier")

input_text = st.text_input('Text:')

####################
# Google Translate API
####################

translator = Translator()
input_text = translator.translate(
    input_text,dest= "en"
)
    
input_text = input_text.text

####################
#Select Precision and Inference Method
####################

df = pd.DataFrame()
df["lang"] = ["en"]

precision = st.sidebar.selectBox("Select Precision:",("16 Bit","32 Bit")
)

inference = st.sidebar.selectBox("Inference Method:",("ONNX","TensorRT")
)

if st.button('Show Selected Configuration'):
    st.subheader("Selected Configuration:")
    st.write("Precision: ",precision) 
    st.write("Inference: ",inference)

st.subheader("Results")

def result(x):
    """
    Function to classify the comment toxicity based on the probability and given threshold
    
    params: x(float) - Probability of Toxicity
    """
    if x >= 0.4:
        st.write("Toxic")
        
    else:
        st.write("Non Toxic")
        
####################
# Implement Selected Configuration
####################
        
if precision=="16 Bit":
    if inference=="ONNX":
        df["comment_text"] = [input_text]

        predictions = run_onnx_inference(
                                        onnx_model_path = "/workspace/data/multilingual-text-classifier/output models/mBERT_lightning_fp16_2GPU.onnx",stage="inference",df_test = df
                                        )
        predictions = torch.sigmoid(torch.tensor(predictions))
        st.write(input_text)
        st.write(predictions)
        result(predictions)

    if inference=="TensorRT":
        df["content"] = [input_text]

        predictions = run_trt_inference(
                                        trt_model_path = "/workspace/data/multilingual-text-classifier/output models/mBERT_lightning_fp16_bs16.engine",df_test = df
                                        )
        
        predictions = predictions.astype("float32")
        predictions = torch.sigmoid(torch.tensor(predictions))
        st.write(input_text)
        st.write(predictions)
        result(predictions)

if precision=="32 Bit":
    if inference=="ONNX":
        df["comment_text"] = [input_text]

        predictions = run_onnx_inference(
                                        onnx_model_path = "/workspace/data/multilingual-text-classifier/output models/mBERT_fp32.onnx",df_test = df
                                        )
        predictions = torch.sigmoid(torch.tensor(predictions))
        st.write(input_text)
        st.write(predictions)
        result(predictions)

    if inference=="TensorRT":
        df["content"] = [input_text]

        predictions = run_trt_inference(
                                        trt_model_path = "/workspace/data/multilingual-text-classifier/output models/mBERT_fp32.engine",df_test = df
                                        )
        
        predictions = predictions.astype("float32")
        predictions = torch.sigmoid(torch.tensor(predictions))
        st.write(input_text)
        st.write(predictions)
        result(predictions)
        
####################
# Take Feedback
####################
        
st.subheader("Feedback:")
Feedback = st.radio(
     "Are you satisfied with the results?",('Yes','No'))

st.write("Thanks for the Feedback!")

错误

-------------------------------------------------------------------
PyCUDA ERROR: The context stack was not empty upon module cleanup.
-------------------------------------------------------------------
A context was still active when the context stack was being
cleaned up. At this point in our execution,CUDA may already
have been deinitialized,so there is no way we can finish
cleanly. The program will be aborted Now.
Use Context.pop() to avoid this problem.
-------------------------------------------------------------------
Aborted (core dumped)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。