![](/img/trans.png)
[英]HuggingFace Transformers For Text Generation with CTRL with Google Colab's free GPU
[英]Is that possible to reset / empty / free up Google Colab notebook GPU VRAM? Without restarting the session
目前我正在尝试在我的 Google Colab 上运行 Whisper。
它会引发 GPU 内存错误。 但是在抛出错误后,GPU 内存使用率仍然是最大的
我可能不知道 100 个问题,但给出的答案都不起作用
我需要一种无需重新启动会话即可释放 GPU 内存的方法,从而避免删除所有下载的数据
下面来看看笔记本目前的状态。 您看到错误抛出,但 GPU 内存仍然最大
这是 Google Colab 的全部代码
!pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117
!pip install git+https://github.com/openai/whisper.git
import os
# Add folders
checkContentFolder = os.path.exists("content")
checkDownLoadFolder = os.path.exists("download")
if not checkContentFolder:
os.mkdir("content")
if not checkDownLoadFolder:
os.mkdir("download")
import whisper
from pathlib import Path
from whisper.utils import write_srt
import pandas as pd
def main():
# transcribe the audio
#model = whisper.load_model("large")
model = whisper.load_model("large-v1")
#model = whisper.load_model("../input/whisper2/large-v1.pt")
transcribe_name_begin="oop";
sub_folder_name="/download/oop/"
import os
if not os.path.isdir(sub_folder_name):
os.makedirs(sub_folder_name)
_compression_ratio_threshold = 2.4
for lectureId in range(142, 143):
transcribePath=f"../content/"+transcribe_name_begin+str(lectureId)+".mp3";
result = model.transcribe(transcribePath,
language="en",
beam_size=9,
initial_prompt="Welcome to the Software Engineering Courses channel.",
best_of=9,verbose=True,temperature=0.0,compression_ratio_threshold=_compression_ratio_threshold)
#result = model.transcribe("../input/whisper2/lecture_"+str(lectureId)+".mp3",language="en",beam_size=5,initial_prompt="Welcome to the Software Engineering Courses channel.",best_of=5,verbose=True,temperature=0.0)
# save SRT
language = result["language"]
sub_name = sub_folder_name+transcribe_name_begin+str(lectureId)+".srt"
with open(sub_name, "w", encoding="utf-8") as srt:
write_srt(result["segments"], file=srt)
# Save output
writing_lut = {
'.txt': whisper.utils.write_txt,
'.vtt': whisper.utils.write_vtt,
'.srt': whisper.utils.write_txt,
}
output_type="All"
if output_type == "All":
for suffix, write_suffix in writing_lut.items():
transcript_local_path =sub_folder_name+transcribe_name_begin+str(lectureId) +suffix
with open(transcript_local_path, "w", encoding="utf-8") as f:
write_suffix(result["segments"], file=f)
try:
transcript_drive_path =file_name
except:
print(f"**Transcript file created: {transcript_local_path}**")
else:
transcript_local_path =sub_folder_name+transcribe_name_begin+str(lectureId) +output_type
with open(transcript_local_path, "w", encoding="utf-8") as f:
writing_lut[output_type](result["segments"], file=f)
if __name__ == "__main__":
main()
有时这个问题的解决方案对我有用:
from numba import cuda
device = cuda.get_current_device()
device.reset()
但有时会话在重置后崩溃了:(
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.