colab-hf-chat 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -48
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,67 +1,38 @@
|
|
|
1
|
-
#
|
|
1
|
+
# colab-hf-chat
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
在 Google Colab GPU 上运行 Hugging Face 聊天模型,通过 SSH 转发在本机使用 vLLM 的 OpenAI 兼容 API。CLI 可自动安装 Google Colab CLI、引导 Google 授权,并显示账户剩余 Compute Units(CU)。
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
npm install -g ./colab-hf-chat-0.1.0.tgz
|
|
7
|
-
colab-hf-chat
|
|
8
|
-
```
|
|
9
|
-
|
|
10
|
-
macOS 和 Linux 直接运行。Windows 原生 Node.js 可以安装同一个 npm 包,运行时需要已经初始化的 WSL 2 Linux 发行版。Ubuntu 或 WSL 中缺少系统工具时,运行 `sudo apt install openssh-client curl`。本地 API 使用回环地址。Windows 访问 WSL 服务依赖 localhost 转发。
|
|
11
|
-
|
|
12
|
-
工具会安装 Colab CLI、引导 Google OAuth、显示剩余 CU,并询问 Hugging Face 模型 ID、GPU 和本地端口。等待 **API 已就绪** 后,在 OpenAI 兼容客户端填入显示的 Base URL 和模型 ID。如果客户端要求 API Key,填 `local`。退出前按 **Ctrl+C** 释放本次 GPU 会话。仅查询额度可运行 `colab-hf-chat usage`。
|
|
13
|
-
|
|
14
|
-
## Hugging Face 模型试跑与公网 API
|
|
5
|
+
## 安装和启动
|
|
15
6
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## Colab 查询和试跑
|
|
7
|
+
需要 Node.js 18+。macOS 和 Linux 使用本机 Bash、curl 和 OpenSSH。Windows 使用已初始化的 WSL 2 Linux 发行版,并需要 WSL 的 localhost 转发。
|
|
19
8
|
|
|
20
9
|
```bash
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
./deploy.sh colab
|
|
10
|
+
npm install -g colab-hf-chat --registry=https://registry.npmjs.org/
|
|
11
|
+
colab-hf-chat
|
|
24
12
|
```
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
14
|
+
1. 首次使用时,按提示用自己的 Google 账号授权 Colab CLI。
|
|
15
|
+
2. 输入公开的 Hugging Face 聊天模型 ID。默认使用 `Qwen/Qwen2.5-0.5B-Instruct`、L4 GPU 和本地端口 `8000`。
|
|
16
|
+
3. 看到 **API 已就绪** 后,将 OpenAI 兼容客户端的 Base URL 设为 `http://127.0.0.1:8000/v1`,模型填你输入的模型 ID。若客户端要求 API Key,可填 `local`。
|
|
17
|
+
4. 使用结束后按 **Ctrl+C** 释放 GPU 会话。
|
|
29
18
|
|
|
30
|
-
|
|
31
|
-
hf auth login
|
|
32
|
-
./deploy.sh publish YOUR_HF_USERNAME/hf-text-api
|
|
33
|
-
```
|
|
19
|
+
首次启动会安装 vLLM 并下载模型权重。模型需受 vLLM 支持,并能放入所选 GPU 的显存。GPU 可用性由 Colab 决定。API 监听本机回环地址。
|
|
34
20
|
|
|
35
|
-
|
|
21
|
+
## 调用示例
|
|
36
22
|
|
|
37
23
|
```bash
|
|
38
|
-
curl -fsS
|
|
24
|
+
curl -fsS http://127.0.0.1:8000/v1/models
|
|
25
|
+
curl -fsS http://127.0.0.1:8000/v1/chat/completions \
|
|
39
26
|
-H 'Content-Type: application/json' \
|
|
40
|
-
-d '{"
|
|
27
|
+
-d '{"model":"Qwen/Qwen2.5-0.5B-Instruct","messages":[{"role":"user","content":"你好"}],"max_tokens":64}'
|
|
41
28
|
```
|
|
42
29
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
## 更换模型
|
|
46
|
-
|
|
47
|
-
支持带 `tokenizer.json`、具有 `id2label` 的 `config.json` 和匹配的 ONNX 文件的单文本分类模型。ONNX 输入需兼容 `input_ids`、`attention_mask` 或 `token_type_ids`,首个输出应为分类 logits。设置 `MODEL_ID`、可选的 `MODEL_REVISION` 和 `MODEL_FILE`。Colab 从本地命令环境接收上述配置,公网 API 从 Space Settings 的 Variables 接收配置。生成、图像或语音模型需要更换推理代码和请求格式。
|
|
48
|
-
|
|
49
|
-
## Colab GPU 与 OpenAI 兼容聊天 API
|
|
30
|
+
## 只查 Colab 额度
|
|
50
31
|
|
|
51
32
|
```bash
|
|
52
|
-
|
|
53
|
-
./gpu-chat.sh L4 Qwen/Qwen2.5-0.5B-Instruct 8000
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
脚本申请 Colab GPU,安装 vLLM,并通过 Colab CLI 的 SSH 转发把 API 接到本机。默认模型为可公开下载的 Qwen 聊天模型。看到 **API 已就绪** 后,在另一个终端验证:
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
curl -fsS http://127.0.0.1:8000/v1/models
|
|
60
|
-
curl -fsS http://127.0.0.1:8000/v1/chat/completions \
|
|
61
|
-
-H 'Content-Type: application/json' \
|
|
62
|
-
-d '{"model":"Qwen/Qwen2.5-0.5B-Instruct","messages":[{"role":"user","content":"用一句话介绍你自己"}],"max_tokens":64}'
|
|
33
|
+
colab-hf-chat usage
|
|
63
34
|
```
|
|
64
35
|
|
|
65
|
-
|
|
36
|
+
显示剩余 CU、当前每小时消耗和活跃会话数。此命令不申请 GPU。
|
|
66
37
|
|
|
67
|
-
|
|
38
|
+
本项目是独立 CLI,使用 [Google Colab CLI](https://github.com/googlecolab/google-colab-cli) 和 [vLLM](https://docs.vllm.ai/)。
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "colab-hf-chat",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Run Hugging Face chat models on Colab GPUs with vLLM, a localhost OpenAI-compatible API, and Colab compute-unit reporting.",
|
|
5
5
|
"bin": {
|
|
6
6
|
"colab-hf-chat": "cli.cjs"
|
|
7
7
|
},
|