Spaces:
Paused
Paused
| title: DevMode | |
| emoji: 😅 | |
| colorFrom: indigo | |
| colorTo: blue | |
| sdk: docker | |
| pinned: false | |
| license: apache-2.0 | |
| Dev Mode 是 Huggingface Space 的付费功能,支持通过 VSCode Remote SSH 插件连接和管理 Space。 | |
| 本 Demo 展示如何在免费的 Space 中实现类似 Dev Mode 的功能。 | |
| ### 一、普通 SSH 连接 | |
| Dumplicate 当前 Space,选择 public,填入自定义 `PASSWORD`(必填) | |
| 下载与系统相匹配的 [glider](https://github.com/nadoo/glider/releases)工具,在本地执行命令: | |
| ``` | |
| glider --listen socks5://:22022 -forward wss://$MY_SPACE.hf.space/control,trojanc://{MY_PASSWORD}@ | |
| ``` | |
| `$MY_SPACE` 可以在 Space 右上角 [...] - Embed this Space - Direct URL 中找到。例如当前 Space 是 `tastypear-devmode-demo` | |
| `$PASSWORD` 是刚才设置的密码。 | |
| 最后使用 ssh 通过代理 `socks5://localhost:22022` 连接到 `ubuntu@localhost:22022`,账户无密码。 | |
| 现代 ssh 客户端都支持通过代理连接,你可以使用 Xshell。 | |
| ### 二、使用 VSCode 管理 Space | |
| 在 VSCode 内安装 Remote SSH 插件。 | |
| 在左下角`管理-命令面板`(Ctrl+Shift+P)中 `Remte-SSH: 连接到主机 - 配置 SSH 主机`,选择一个你要使用的 `.ssh\config`(通常是 `C:\Users\用户名\.ssh\config`) | |
| 这里提供两种通过 socks5 连接到主机的配置: | |
| ``` | |
| Host Dev-Mode-Config-ncat | |
| ProxyCommand "D:\…\ncat.exe" --proxy-type socks5 --proxy localhost:22022 %h %p | |
| HostName localhost | |
| User ubuntu | |
| Port 22022 | |
| Host Dev-Mode-Config-connect | |
| ProxyCommand "D:\…\connect.exe" -S localhost:22022 %h %p | |
| HostName localhost | |
| User ubuntu | |
| Port 22022 | |
| ``` | |
| ncat.exe 是 [nmap](https://nmap.org/download#windows) 的一部分,安装时可以单独选择。 | |
| connect.exe 通常与 git 客户端在一起,位于`mingw64/bin`下。(如果你在本机中找不到 connect.exe,那么就使用 ncat 方案吧。) | |
| Linux 用户请使用 nc 自行尝试。 | |
| 如果因重启 Space 导致 VSCode 无法连接,请删除本地 `.ssh\known_hosts` 文件后重试。 | |
| ### 三、连接后的注意事项 | |
| glider 的连接依赖 nginx 反向代理功能。你可以修改 nginx.conf 文件来更换主页,但如果配置有误导致 nginx 重启失败,你将因为 glider 断开与 Space 彻底失联。 | |
| 为了防止这种情况发生,在打算重启 nginx 前,你应该使用隧道工具为 22022 端口建立独立的外部访问途径。 | |
| 以 [bore](https://github.com/ekzhang/bore/releases) 工具为例,在 Space 中执行: | |
| ```bash | |
| wget https://github.com/ekzhang/bore/releases/download/v0.5.1/bore-v0.5.1-x86_64-unknown-linux-musl.tar.gz | |
| tar -xvf bore*.tar.gz && rm bore*.tar.gz && chmod +x bore | |
| nohup ./bore local 22022 --to bore.pub & | |
| ``` | |
| ```bash | |
| # 查看 bore 分配的转发端口 | |
| tail nohup.out | |
| ``` | |
| 然后通过 ssh 客户端连接 `ubuntu@bore.pub:port`,然后在这个 session 中尝试重启 nginx: | |
| ```bash | |
| ps -ef | grep 'nginx' | grep -v grep | awk '{print $2}' | xargs -r kill -9 && nohup /usr/sbin/nginx -c /home/ubuntu/nginx.conf >/dev/null 2>&1 & | |
| ``` | |
| 你也可以使用 [wstunnel](https://github.com/erebe/wstunnel) 自托管隧道,这样即使将 Space 设置为 private 也能继续连接,而不依赖 glider(不过可能会因为服务端不稳定而失联,风险自负)。 | |
| ⚠警告!不要使用 cloudflared 建立隧道,官方可能限制该工具从而导致 Space 断网,重建也无法恢复。 | |
| ⚠警告!不要使用 proot 模拟 root 环境。理由同上。 | |
| ### 附录:Space 跑分 | |
| ``` | |
| ubuntu@localhost:~$ wget -qO- yabs.sh | bash | |
| # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## # | |
| # Yet-Another-Bench-Script # | |
| # v2024-06-09 # | |
| # https://github.com/masonr/yet-another-bench-script # | |
| # ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## # | |
| Sun Jun 30 20:05:16 UTC 2024 | |
| Basic System Information: | |
| --------------------------------- | |
| Uptime : 12 days, 2 hours, 51 minutes | |
| Processor : Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz | |
| CPU cores : 16 @ 3499.737 MHz | |
| AES-NI : ✔ Enabled | |
| VM-x/AMD-V : ❌ Disabled | |
| RAM : 123.8 GiB | |
| Swap : 884.8 GiB | |
| Disk : 1.7 TiB | |
| Distro : Ubuntu 24.04 LTS | |
| Kernel : 5.10.217-205.860.amzn2.x86_64 | |
| VM Type : | |
| IPv4/IPv6 : ✔ Online / ❌ Offline | |
| IPv4 Network Information: | |
| --------------------------------- | |
| ISP : Amazon.com, Inc. | |
| ASN : AS14618 Amazon.com, Inc. | |
| Host : AWS EC2 (us-east-1) | |
| Location : Ashburn, Virginia (VA) | |
| Country : United States | |
| fio Disk Speed Tests (Mixed R/W 50/50) (Partition overlay): | |
| --------------------------------- | |
| Block Size | 4k (IOPS) | 64k (IOPS) | |
| ------ | --- ---- | ---- ---- | |
| Read | 6.15 MB/s (1.5k) | 65.86 MB/s (1.0k) | |
| Write | 6.14 MB/s (1.5k) | 66.31 MB/s (1.0k) | |
| Total | 12.29 MB/s (3.0k) | 132.18 MB/s (2.0k) | |
| | | | |
| Block Size | 512k (IOPS) | 1m (IOPS) | |
| ------ | --- ---- | ---- ---- | |
| Read | 63.65 MB/s (124) | 62.58 MB/s (61) | |
| Write | 66.72 MB/s (130) | 67.04 MB/s (65) | |
| Total | 130.38 MB/s (254) | 129.63 MB/s (126) | |
| iperf3 Network Speed Tests (IPv4): | |
| --------------------------------- | |
| Provider | Location (Link) | Send Speed | Recv Speed | Ping | |
| ----- | ----- | ---- | ---- | ---- | |
| Eranium | Amsterdam, NL (100G) | 1.72 Gbits/sec | 1.96 Gbits/sec | -- | |
| Uztelecom | Tashkent, UZ (10G) | 807 Mbits/sec | 931 Mbits/sec | -- | |
| Leaseweb | Singapore, SG (10G) | 620 Mbits/sec | 630 Mbits/sec | -- | |
| Clouvider | Los Angeles, CA, US (10G) | 1.84 Gbits/sec | 2.93 Gbits/sec | -- | |
| Leaseweb | NYC, NY, US (10G) | 3.16 Gbits/sec | 9.30 Gbits/sec | -- | |
| Edgoo | Sao Paulo, BR (1G) | 1.13 Gbits/sec | 1.39 Gbits/sec | -- | |
| Geekbench 6 Benchmark Test: | |
| --------------------------------- | |
| Test | Value | |
| | | |
| Single Core | 1532 | |
| Multi Core | 1846 | |
| Full Test | https://browser.geekbench.com/v6/cpu/6734087 | |
| YABS completed in 13 min 26 sec | |
| ``` |