← Back to list

wandb 无法连接访问了?

最近跑实验发现 wandb 连接不上了,怕不是 GFW 被封了,当然也有可能是 wandb 禁止中国的 IP 访问了🤡。

jackal · 2025-06-04 00:57 · 4 claps · 8.3 min read
#training #ai #wandb #swanlab
Open on Medium ↗
Wiki topics: AI · AI · General

wandb 无法连接访问了?

最近跑实验发现 wandb 连接不上了,怕不是 GFW 被封了,当然也有可能是 wandb 禁止中国的 IP 访问了🤡。

wandb: Network error (ConnectTimeout), entering retry loop.
wandb: ERROR Run initialization has timed out after 90.0 sec. Please try increasing the timeout with the `init_timeout` setting: `wandb.init(settings=wandb.Settings(init_timeout=120))`.
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.13/asyncio/tasks.py", line 507, in wait_for
    return await fut
           ^^^^^^^^^
  File "/root/miniconda3/lib/python3.13/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/root/miniconda3/lib/python3.13/site-packages/wandb/sdk/mailbox/response_handle.py", line 109, in wait_async
    await asyncio.wait_for(evt.wait(), timeout=timeout)
  File "/root/miniconda3/lib/python3.13/asyncio/tasks.py", line 506, in wait_for
    async with timeouts.timeout(timeout):
               ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/root/miniconda3/lib/python3.13/asyncio/timeouts.py", line 116, in __aexit__
    raise TimeoutError from exc_val
TimeoutError

在本地电脑上开梯子是可以正常访问 wandb.ai 的,但是一般训练都是跑在远程服务器上或者是开发容器上面,比如在 aliyun 或者 autodl 上开一个训练机,都没有代理环境,且经常是跑完训练就把服务器关了,用的时候再重新开一台,每次配置都很麻烦,非常难顶。

下面介绍一下我配置服务器代理的方案以及 wandb 的替代方案,毕竟打工人的炼丹不能停啊😭。

服务器配置稳定代理环境

对于安装有 GUI 桌面的服务器,可以直接使用 Clash Vege,如果未安装则可以按照下面的方案配置

准备 Clash 配置文件

不管你使用的什么机场,先把其提供的配置文件下载下来,命名为 clash.yaml。然后需要修改一下其中的 tundns 配置,示例如下:

mixed-port: 7890
allow-lan: false
bind-address: "*"
mode: rule
log-level: info
external-controller: "0.0.0.0:9090"
unified-delay: true
tcp-concurrent: true
# 需要开启 TUN 配置
tun:
  enable: true
  stack: system
  dns-hijack:
    - any:53
  auto-route: true
  auto-redir: true
  auto-detect-interface: true
# 开启 DNS 配置, 且使用 fake-ip 模式
dns:
  enable: true
  listen: 0.0.0.0:1053
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  default-nameserver:
    - 223.5.5.5
    - 119.29.29.29
  nameserver:
    - 223.5.5.5
    - 119.29.29.29

修改成功后,将修改后的文件同步到目标服务器上,命名为 clash.yaml

安装 TPClash

首先下载 tpclash 到本地,然后将其上传到目标服务器上。或者直接在目标服务器上执行以下命令下载(但是大概率下不下来):

wget <https://github.com/TPClash/tpclash/releases/download/v0.2.6/tpclash-mihomo-linux-amd64-v3>

然后使用以下命令为可执行文件修改可执行权限

chmod +x tpclash-mihomo-linux-amd64-v3

将上面获取的配置文件移动到 /etc/tpclash/ 目录下

mkdir -p /etc/tpclash && mv clash.yaml /etc/tpclash/

启动 TPClash

启动 tpclash,tpclash 会自动为我们配置 systemd。

./tpclash-premium-linux-amd64-v3 install --config /etc/tpclash/clash.yaml
# 这里 --config 参数后面对应的就是 clash.yaml 配置文件的绝对路径

执行成功后,我们可以执行 cat /etc/systemd/system/tpclash.service 查看生成的配置文件。然后启动 systemd 服务

systemctl enable tpclash 
systemctl start tpclash

启动成功后,便可以通过 systemctl status tpclash 查看服务状态

(base) root@jackal:~# systemctl status tpclash
● tpclash.service - Transparent proxy tool for Clash
     Loaded: loaded (/etc/systemd/system/tpclash.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2025-06-03 14:19:33 CST; 5s ago
   Main PID: 190836 (tpclash)
      Tasks: 20 (limit: 8628)
     Memory: 56.3M
        CPU: 318ms
     CGroup: /system.slice/tpclash.service
             ├─190836 /usr/local/bin/tpclash --home /data/clash --config /etc/tpclash/clash.yaml --ui yacd --check-interval 2m0s
             └─190844 /data/clash/xclash -f /data/clash/xclash.yaml -d /data/clash -ext-ui /data/clash/yacd

如果显示为 running状态则代表运行成功,下面我们测试代理的效果。使用 curl ipinfo.io

(base) root@jackal:~# curl ipinfo.io
{
  "ip": "18.187.192.19",
  "hostname": "ec2-18-183-192-19.ap-northeast-1.compute.amazonaws.com",
  "city": "Tokyo",
  "region": "Tokyo",
  "country": "JP",
  "loc": "35.6895,139.6917",
  "org": "AS16509 Amazon.com, Inc.",
  "postal": "101-8656",
  "timezone": "Asia/Tokyo",
  "readme": "<https://ipinfo.io/missingauth>"
}

一切都很完美!配置成功后就可以稳定连接 wandb 了。

TPClash 控制面板

使用 IP:9090/ui 可以看到 tpclash 自带的网页面板,就跟本机安装的 Clash 一样。

替代方案

我研究了一下,在国内不开代理是能访问 wandb.ai 的,但是 python 包无法连接到 wandb 的服务,说明可能是 wandb 对中国地区有一定的限制措施,就像 Claude 一样(shit🤪)。目前配置代理苟着用 wandb 也非长久之计啊,说不定哪天就像 Claude 一样给我账号封了,那我是真成地仙了(实验数据给没了)。

目前保险方案是继续 tensorboard ,不过比较鸡肋,只能管理一个项目下的实验。

看了一下 wandb issue 里面有不少人都遇到有这个问题,然后也有不少人推荐使用 swanlabwandb/wandb#9938)替代。

看了一下,是个国内团队开发的,感觉非常不错呀,功能也都符合我的需求。(之前也是用 wandb 用入魔了,没关注到还有其它类似平台)

SwanLab

24 年开始开发的,还在持续迭代中。(是个长期稳定项目)

调研了一圈,开始着手迁移到 swanlab 了。


메타데이터
post_id
ff39b487684f
slug
wandb-无法连接访问了-ff39b487684f
url
https://medium.com/@ideaflowx/wandb-%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E8%AE%BF%E9%97%AE%E4%BA%86-ff39b487684f
canonical_url
https://medium.com/@ideaflowx/wandb-%E6%97%A0%E6%B3%95%E8%BF%9E%E6%8E%A5%E8%AE%BF%E9%97%AE%E4%BA%86-ff39b487684f
author_url
https://medium.com/@ideaflowx
status
ok
fetched_at
2026-07-19 14:50:31