Google Colab, but in your favourite terminal
Google Colab, but in your favourite terminal
Google Colab,现在可以在你最喜欢的终端里使用了
While some of my recent posts have involved using the Colab extension for VS Code and the Antigravity IDE, I actually prefer working in the terminal and Vim. The new Colab CLI finally lets me work in my natural habitat, and it opens the door for autonomous workflows! 虽然我最近的一些文章涉及使用 VS Code 的 Colab 扩展和 Antigravity IDE,但我实际上更喜欢在终端和 Vim 中工作。新的 Colab CLI 终于让我可以在自己舒适的环境中工作,并为自动化工作流打开了大门!
Setup
设置
Currently, installation is handled via pip or uv. It’s straightforward, though, I’m holding out hope for a brew formula in the future: 目前,安装可以通过 pip 或 uv 完成。过程非常简单,不过我还是希望能早日看到 brew 的安装方式:
uv tool install google-colab-cli
I’m testing Version: 0.6.dev7+g510115b0c inside Ghostty. The Colab CLI is pretty solid, but I do have some feedback and nitpicks I’d like to share (but more on that later). 我正在 Ghostty 中测试版本:0.6.dev7+g510115b0c。Colab CLI 非常稳健,但我确实有一些反馈和细节想分享(稍后再谈)。
Creating a new session
创建新会话
Creating a session is simple: 创建会话很简单:
colab new [-s SESSION_NAME] [--gpu T4|L4|A100|H100] [--tpu v5e1|v6e1]
- SESSION_NAME: This is optional. If you leave it blank, the CLI generates a random unique ID for you.
- SESSION_NAME:这是可选的。如果留空,CLI 会为你生成一个随机的唯一 ID。
- —gpu and —tpu: The hardware accelerator flags are optional, but omitting them defaults to a standard CPU-only instance. The specific accelerator chips you can request depend on your Colab tier, which you can check via
colab pay. - —gpu 和 —tpu:硬件加速器标志是可选的,但如果省略,默认会使用标准的仅 CPU 实例。你可以请求的具体加速器芯片取决于你的 Colab 等级,你可以通过
colab pay查看。
NOTE: If you only have one active session, the CLI targets it by default. This makes the -s flag unnecessary for subsequent commands. 注意:如果你只有一个活动会话,CLI 会默认指向它。这使得后续命令无需再使用 -s 标志。
Testing Colab CLI’s capabilities
测试 Colab CLI 的功能
CLI certainly sounds cool, but how does it handle artifacts and images? More importantly, how debuggable is it? I decided to find out by running a Fashion MNIST PyTorch example. CLI 听起来确实很酷,但它如何处理产出物(artifacts)和图像?更重要的是,它的可调试性如何?我决定通过运行一个 Fashion MNIST PyTorch 示例来一探究竟。
Handling artifacts
处理产出物
To get started, I installed my requirements using colab install torch torchvision matplotlib. If you prefer a more standard approach, you can also use colab install -r requirements.txt. Once the environment was ready, I executed the training script using colab exec -f ./fashion_mnist_TRAIN.py and here’s the output:
首先,我使用 colab install torch torchvision matplotlib 安装了依赖。如果你更喜欢标准做法,也可以使用 colab install -r requirements.txt。环境准备好后,我使用 colab exec -f ./fashion_mnist_TRAIN.py 执行了训练脚本,输出如下:
(Output omitted for brevity) (此处省略输出内容)
When the training finished, the PyTorch model is saved in the Colab instance. To manage these files, you have two solid options: 训练完成后,PyTorch 模型会保存在 Colab 实例中。要管理这些文件,你有两个可靠的选择:
- Google Drive: Use
colab drivemount [PATH]to mount your Google Drive to save artifacts directly to a persistent cloud filesystem. - Google Drive:使用
colab drivemount [PATH]挂载你的 Google Drive,将产出物直接保存到持久化的云文件系统中。 - Local Download: Use
colab download REMOTE_FILE LOCAL_FILEto pull the model back to your local machine. - 本地下载:使用
colab download REMOTE_FILE LOCAL_FILE将模型拉取回你的本地机器。
Working with images
处理图像
I was pleasantly surprised to find that images displayed just fine! Despite being a self-proclaimed shell aficionado, I had rarely worked with images in a terminal environment and didn’t realize how seamless this could be. When I ran the inference script with colab exec -f ./fashion_mnist_PREDICT.py, and the CLI automatically handled the visual output:
我惊喜地发现图像显示得非常完美!尽管我自诩为 Shell 爱好者,但我很少在终端环境中处理图像,也没意识到这竟然可以如此顺畅。当我使用 colab exec -f ./fashion_mnist_PREDICT.py 运行推理脚本时,CLI 自动处理了视觉输出:
NOTE: Here are the links to the training script and inference script. 注意:这里是训练脚本和推理脚本的链接。
Debugging
调试
Debugging Colab jobs is arguably easier than before because you can jump directly into a running instance using colab console:
调试 Colab 任务可以说比以前更容易了,因为你可以使用 colab console 直接进入正在运行的实例:
Once you shell into the environment, you can inspect downloaded files, verify artifacts, or install additional dependencies on the fly. If you need to keep a record of your work, you can export your logs and session history using colab log -o SESSION_HISTORY_FILE. This is particularly useful if you want to save your history directly into a mounted Google Drive filesystem for long-term storage or later review.
一旦进入环境,你可以检查下载的文件、验证产出物,或即时安装额外的依赖。如果你需要记录工作,可以使用 colab log -o SESSION_HISTORY_FILE 导出日志和会话历史。如果你想将历史记录直接保存到挂载的 Google Drive 文件系统中以便长期存储或日后查看,这特别有用。
COLAB_SKILL.md
COLAB_SKILL.md
The resurgence of CLI tools is driven by their efficiency over traditional GUIs. While GUIs are designed for human intuition and rely on visual cues, these elements represent noise that an AI agent must filter out. LLMs are already great with text and hence the input & output formats of a CLI are ideal for agents and machines to interpret. In fact, the most powerful way to leverage the Colab CLI is through autonomous agents! Colab CLI’s repo provides a COLAB_SKILL.md file for you to get started for that agentic integration.
CLI 工具的复兴源于它们相对于传统 GUI 的效率优势。虽然 GUI 是为人类直觉设计的并依赖视觉线索,但这些元素对于 AI 智能体来说是需要过滤的“噪音”。LLM 已经非常擅长处理文本,因此 CLI 的输入输出格式非常适合智能体和机器进行解读。事实上,利用 Colab CLI 最强大的方式是通过自主智能体!Colab CLI 的仓库提供了一个 COLAB_SKILL.md 文件,帮助你开始进行这种智能体集成。
Issues & nitpicks
问题与不足
As previously mentioned, the Colab CLI is still being developed, so there’s bound some issues here and there. Here are some that I’ve noticed and would love to see fixed: 如前所述,Colab CLI 仍在开发中,因此难免会有一些问题。以下是我注意到并希望看到修复的一些点:
- Session Timeouts: Relatively short timeouts and automatic pruning can disrupt productivity. While my personal impact has been minimal, this can be a significant hurdle for users with longer running tasks.
- 会话超时:相对较短的超时时间和自动清理可能会影响生产力。虽然对我个人的影响很小,但这对于运行较长任务的用户来说可能是一个重大障碍。
- Interface Disconnects: CLI sessions shows up as “Unknown notebook” in Colab Web and are invisible in the Antigravity IDE or VS Code extension. I’ve filed a GitHub Issue detailing this lack of cross-tool visibility.
- 界面断连:CLI 会话在 Colab Web 中显示为“Unknown notebook”,并且在 Antigravity IDE 或 VS Code 扩展中不可见。我已经提交了一个 GitHub Issue,详细说明了这种跨工具可见性缺失的问题。
- Hardware Parity: Colab Web and IDE extension now offers NVIDIA G4 (Blackwell) instances with 96GB of VRAM. To support high-performance AI workloads, the CLI should offer parity with these newer hardware tiers.
- 硬件对等:Colab Web 和 IDE 扩展现在提供具有 96GB VRAM 的 NVIDIA G4 (Blackwell) 实例。为了支持高性能 AI 工作负载,CLI 应该提供与这些较新硬件等级的对等支持。
Summary
总结
The Colab CLI is a significant step forward for developers who prefer the speed and focus of the terminal over a traditional browser-based UI or IDE. By bringing the power of Google’s cloud hardware into a local, shell-based environment, it successfully… 对于那些比起传统的基于浏览器的 UI 或 IDE,更喜欢终端的速度和专注感的开发者来说,Colab CLI 是向前迈出的重要一步。通过将 Google 云硬件的强大功能引入本地 Shell 环境,它成功地……