TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Auto-unloading models using __init_subclass__ (Python)

1 点作者 matroid超过 1 年前

1 comment

matroid超过 1 年前
I wanted functionality where GPU VRAM isn&#x27;t constantly hogged while I&#x27;m serving a PyTorch model, so that I could simultaneously train stuff.<p>I wanted a solution which was agnostic to the type of the model, with respect to loading and inferring.<p>So I made this AutoUnloadModel class that unloads the model if it hasn&#x27;t been used for some period. I used __init_subclass__ to ensure that all the details regarding timers, locks etc are hidden from the subclass.<p>I found __init_subclass__ very cool for this job, which is the reason I&#x27;m sharing this. Thanks!