Skip to content

Commit 6aaec49

Browse files
committed
docs: 1. 将about linux移动到了about windows附近(上方) 2. 日积月累了torch.cuda.empty_cache()
1 parent 7bb7899 commit 6aaec49

File tree

1 file changed

+51
-25
lines changed

1 file changed

+51
-25
lines changed

Solutions/Other-Accumulation-SomeTips.md

Lines changed: 51 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,30 @@ tags: [其他, 小杂, 知识, 中等, Github, HTML, Windows, Phone, Python, 双
2626

2727
见到一个B站UP主打包WebView2的[视频](https://www.bilibili.com/video/BV1Aa411j7XV/)
2828

29+
## About Linux
30+
31+
### Ubuntu防火墙
32+
33+
查看当前防火墙状态:
34+
35+
```bash
36+
sudo ufw status
37+
```
38+
39+
```
40+
状态: 激活
41+
42+
至 动作 来自
43+
- -- --
44+
21/tcp (v6) ALLOW Anywhere (v6)
45+
```
46+
47+
开启某个端口并且仅允许单个ip访问:
48+
49+
```bash
50+
sudo ufw allow from 192.168.1.0 to any port 3306
51+
```
52+
2953
## About Windows
3054

3155
### Windows应用商店安装的应用
@@ -292,9 +316,33 @@ https://api.bilibili.com/x/web-interface/view?bvid={BV号}
292316
https://api.bilibili.com/x/web-interface/view?bvid=BV1ak4y1J7j7
293317
```
294318
295-
## About ChatGPT
319+
## About AI
320+
321+
### About PyTorch
322+
323+
#### torch.cuda.empty_cache()
324+
325+
使用```torch.cuda.empty_cache()```命令可以清除```nvidia```显卡中一些已经不使用的显存。在我的[一个实验](https://blog.tisfy.eu.org/2024/01/06/Other-AI-FL-FederatedLearning-ProjectWritingIn1month/)中,它能将显存降个十几个G。
326+
327+
为什么nviDia要使用这么多的额外空间呢?D君这么做一定有他的道理。
328+
329+
以下是来自[ChatGPT](https://chat.openai.com/share/1d5abc7d-c9d4-4961-8e53-f2a76d6d1f86)的解释:
330+
331+
```
332+
torch.cuda.empty_cache() 是 PyTorch 中的一个函数,用于释放由 CUDA 分配器持有但当前未使用的缓存内存。这个函数在管理 GPU 内存方面非常有用,尤其是在处理大型网络或数据时。
333+
334+
当你在 PyTorch 中使用 CUDA 进行运算时,为了提高内存分配的效率,CUDA 分配器会在内存中保留一部分未使用的内存作为缓存。这种方式可以加快后续内存分配的速度,因为分配器可以重用这些已经分配但当前未被使用的内存块,而不是每次都从 GPU 的内存池中申请新的内存。
335+
336+
然而,这种预留机制可能会导致 GPU 的可用内存减少,特别是在处理多个大型模型或数据集的时候。在这种情况下,虽然 GPU 实际上有足够的空闲内存,但由于这部分内存被作为缓存预留,可能会出现内存不足的错误。
337+
338+
使用 torch.cuda.empty_cache() 可以释放这些缓存内存。这个操作会告诉 CUDA 分配器释放并返回所有当前未使用的缓存内存,以便这些内存能够用于其他 GPU 运算。但请注意,这个操作并不会降低 PyTorch 中已分配张量的内存使用量。
339+
340+
关键点是,torch.cuda.empty_cache() 只应在必要时使用,因为频繁地释放和重新分配缓存内存会降低程序的效率。此外,这个操作并不会减少由于模型结构或数据批量大小决定的内存需求。因此,它更多是作为在内存紧张时的一种临时解决方案,而不是一种长期的内存管理策略。
341+
```
342+
343+
### About ChatGPT
296344
297-
### 让ChatGPT模拟派蒙
345+
#### 让ChatGPT模拟派蒙
298346
299347
文件来自[Bilibili@极客湾Geekerwan](https://space.bilibili.com/25876945)的[项目](https://www.bilibili.com/video/BV1bm4y117ba/)
300348
@@ -356,29 +404,7 @@ Word中经常需要插入一些公式,但是很多时候需要在公式的最
356404
357405
讲座地址:[BiliBili@BV1TX4y1s7oe](https://www.bilibili.com/video/BV1TX4y1s7oe/)
358406
359-
## About Linux
360-
361-
### Ubuntu防火墙
362-
363-
查看当前防火墙状态:
364-
365-
```bash
366-
sudo ufw status
367-
```
368-
369-
```
370-
状态: 激活
371-
372-
至 动作 来自
373-
- -- --
374-
21/tcp (v6) ALLOW Anywhere (v6)
375-
```
376-
377-
开启某个端口并且仅允许单个ip访问:
378-
379-
```bash
380-
sudo ufw allow from 192.168.1.0 to any port 3306
381-
```
407+
# End
382408
383409
> 同步发文于CSDN,原创不易,转载请附上[原文链接](https://blog.tisfy.eu.org/2023/02/21/Other-Accumulation-SomeTips)哦~
384410
> [https://blog.tisfy.eu.org/2023/02/21/Other-Accumulation-SomeTips](https://blog.tisfy.eu.org/2023/02/21/Other-Accumulation-SomeTips)

0 commit comments

Comments
 (0)