簡體   English   中英

我可以運行我在 google colab 中使用 simpletransformers 制作的 model,但是當我在 spyder 或 Visual Studio 中運行它時,它會出錯

[英]I can run the model which I made with simpletransformers in google colab, but when I run it in spyder or visual studio, it gives an error

from simpletransformers.classification import ClassificationModel
import torch
Bert_model = ClassificationModel(
    "bert", "bert_model")
a=Bert_model.predict(["kötü"])
print(a)
def run():
    torch.multiprocessing.freeze_support()
    print('loop')


if __name__ == '__main__':
    run()

2022-08-09 09:00:57.159758:W tensorflow/stream_executor/platform/default/dso_loader.cc:64] 無法加載動態庫“cudart64_110.dll”; dlerror: cudart64_110.dll not found2022-08-09 09:00:57.159911: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 0%| | 0/1 [00:00<?, ?it/s]2022-08-09 09:01:03.293148: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] 無法加載動態庫 'cudart64_110.dll '; dlerror: cudart64_110.dll not found 2022-08-09 09:01:03.293547: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. 回溯(最后一次調用):文件“”,第 1 行,在文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py”中,第 116 行,在 spawn_main 退出代碼中= _main(fd, parent_sentinel) 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py”,第 125 行,在 _main prepare(preparation_data) 文件“C:\Users \gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py",第 236 行,准備 _fixup_main_from_path(data['init_main_from_path']) 文件“C:\Users\gokhan\AppData\Local\Programs \Python\Python39\lib\multiprocessing\spawn.py",第 287 行,在 _fixup_main_from_path main_content = runpy.run_path(main_path, File "C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\runpy. py",第 268 行,在 run_path 返回 _run_module_code(code,init_globals,run_name,文件 "C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\runpy.py",第 97 行,在 _run_module_code _run_code(代碼、mod_globals、init_globals、文件“C:\Users\gokhan\ AppData\Local\Programs\Python\Python39\lib\runpy.py",第 87 行,在 _run_code exec(code, run_globals) 文件“C:\Users\gokhan\Desktop\code\python\FLASK\aa.py”中,第 5 行,在 a=Bert_model.predict(["kötü"]) 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\site-packages\simpletransformers\classification\classification_model.py”中,第 2062 行,預測 eval_dataset = self.load_and_cache_examples(文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\site-packages\simpletransformers\classification\classification_model.py”,第 1815 行,在 load_and_cache_examples dataset = ClassificationDataset(文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\site-packages\simpletransformers\classification\classification_utils.py”,第 278 行,在init self.examples,self.labels = build_classification_dataset(文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\site-packages\simpletransformers\classification\classification_utils.py”,第 244 行,在 build_classificati on_dataset with Pool(args.process_count) as p: File "C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py",第 119 行,在 Pool 返回 Pool(processes, initializer ,initargs,maxtasksperchild,文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py”,第 212 行,在init self._repopulate_pool() 文件“C:\Users\ gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\pool.py",第 303 行,在 _repopulate_pool 中返回 self._repopulate_pool_static(self._ctx, self.Process, File "C:\Users\gokhan\AppData\ Local\Programs\Python\Python39\lib\multiprocessing\pool.py”,第 326 行,在 _repopulate_pool_static w.start() 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\ process.py”,第 121 行,開始 self._popen = self._Popen(self) 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\context.py”,第 327 行, 在 _Popen 返回 Popen(process_obj) 文件“C:\Users\gokhan\AppData\Local\Pro 克\Python\Python39\lib\multiprocessing\popen_spawn_win32.py”,第 45 行,在init prep_data = spawn.get_preparation_data(process_obj._name) 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib \multiprocessing\spawn.py”,第 154 行,在 get_preparation_data _check_not_importing_main() 文件“C:\Users\gokhan\AppData\Local\Programs\Python\Python39\lib\multiprocessing\spawn.py”,第 134 行,在 _check_not_importing_main raise RuntimeError(''' RuntimeError: 在當前進程完成其引導階段之前嘗試啟動一個新進程。

    This probably means that you are not using fork to start your
    child processes and you have forgotten to use the proper idiom
    in the main module:

        if __name__ == '__main__':
            freeze_support()
            ...

    The "freeze_support()" line can be omitted if the program
    is not going to be frozen to produce an executable.

我認為該錯誤已經解決了您的問題

設置

if __name__ == '__main__':
        freeze_support()
        ...

在您的 main.py 代碼上對作業進行多線程處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM