谷歌推出 Google Colab CLI:在终端与 AI 代理中零阻力调用云端 GPU/TPU
英文标题:Introducing the Google Colab CLI
谷歌发布了 Google Colab 命令行界面 (CLI),让开发者和 AI 代理能够直接从本地终端连接远程 Colab 运行时并执行代码。该工具支持一行命令申请高性能 GPU 或 TPU(如 A100、T4),远程运行本地 Python 脚本,并可方便地回传模型、数据集与可复现的 .ipynb 日志。CLI 内置了面向 AI 代理的技能文件,可被 Claude Code、Codex 等代理直接使用,实现端到端的远程微调等机器学习工作流。这大大降低了使用云端加速器的摩擦,使 Colab 算力对终端和代理驱动开发更加友好。
114.0 KB
64.8 KB
12.8 KB
496.8 KB
53.1 KB
中文
今天我们正式发布 Google Colab 命令行界面(CLI),它在你的本地终端与远程 Colab 运行时之间架起桥梁,为开发者和 AI 代理提供了一个零摩擦的执行平台。Colab CLI 具备以下特性:
- **零摩擦加速器配置:**立即申请高性能 GPU 或 TPU(例如
colab --gpu A100或colab --gpu T4)。 - **简单的远程执行:**使用
colab exec直接在 Colab 运行时上运行你的本地 Python 脚本和复杂机器学习流水线。 - **无缝产物回传:**通过
colab download与colab log轻松取回模型、数据集以及可重放的.ipynb日志。 - **交互式访问:**使用
colab repl或colab console进入远程 Colab 运行时的交互式环境。
代理驱动的工作流实战
因为 Colab CLI 可以无缝集成到标准终端环境中,所以任何拥有终端访问权限的代理都能使用它。为了帮助你的人工智能助手开箱即用,CLI 内置了一个预打包的 Colab 技能文件,为代理提供即时内建的上下文,使其清楚了解如何使用 CLI。下面我们来看一个用户或代理可能用 Colab CLI 尝试的真实示例。
*请注意,虽然以下示例展示了 Antigravity 代理将 Colab CLI 作为工具使用,但 Colab CLI 同样可以被 Claude Code、Codex 以及其他代理轻松使用。
以下是一个代理如何将 Colab CLI 用于真实机器学习工作流的示例:
微调 Gemma 3-1B
只需几条命令,CLI 就能运行一个端到端的真实 QLoRA 流水线。只需指示 Antigravity(或你选择的代理)构建一个远程微调任务,即可将繁重的计算任务卸载到 GPU,而无需输入任何云配置命令。在这个场景中,我们要求代理使用 Colab CLI 在 Text-to-SQL 数据集上微调 google/gemma-3-1b-it,让模型更擅长生成 SQL 查询。
Antigravity 提示词:
使用 Colab CLI(https://github.com/googlecolab/google-colab-cli)并通过 QLoRA 微调 Gemma 3 1B。配置一个 Colab T4 GPU 实例,安装必要的机器学习包(transformers、datasets、peft、trl 等),远程运行我的本地 finetune_run.py 脚本,下载生成的 safetensors 适配器,保存笔记本日志,然后清理。
Antigravity 执行:
$ colab new --gpu T4
$ colab install transformers datasets peft trl bitsandbytes accelerate
$ colab exec -f finetune_run.py
$ colab log --output gemma_finetune_log.ipynb
$ colab stop
Antigravity 还使用 “colab download” 命令下载适配器模型、适配器配置、分词器配置和分词器,这些文件可用于在本地加载和运行你微调后的模型。现在,你已经拥有一个从本地设备即可提供服务的远程微调模型!
立即试用
Colab CLI 让强大的 Colab 算力变得可访问、可编程并做好代理准备。它轻量且易于被任何基于终端的 AI 代理使用。要亲自开始使用 Colab CLI,请前往 Google Colab CLI GitHub 仓库获取安装说明。
我们非常期待看到它如何加速你的开发流程,也期待看到你和你的代理们会构建出什么!
English / 原文
Today we are announcing the Google Colab Command-Line Interface (CLI), which bridges the gap between your local terminal and remote Colab runtimes, providing a zero-friction execution platform for both developers and AI agents. The Colab CLI offers:
- Zero-Friction Accelerator Provisioning: Request high-powered GPUs or TPUs instantly (e.g.,
colab --gpu A100orcolab --gpu T4). - Simple Remote Execution: Run your local Python scripts and complex ML pipelines directly on Colab runtimes using
colab exec. - Seamless Artifact Recovery: Easily retrieve models, datasets, and replayable
.ipynblogs viacolab downloadandcolab log. - Interactive Access: Drop into an interactive environment on your remote Colab runtime with
colab replorcolab console.
Agent-driven workflows in action
Because the Colab CLI integrates seamlessly into standard terminal environments, it can be used by any agent with terminal access. To ensure your AI assistants can hit the ground running, the CLI includes a prepackaged Colab skill file that provides agents with instant, built-in context on exactly how to leverage the CLI. Let's look at a real life example of something a user or agent might try with the Colab CLI.
*Note that while the example below highlights Antigravity agent using Colab CLI as a tool, Colab CLI can easily be used by Claude Code, Codex, and other agents.
Here is how an Agent can use the Colab CLI for a real-world ML workflow:
Fine-tuning Gemma 3-1B
The CLI can be used to run a real QLoRA pipeline that runs end-to-end with just a handful of commands. Offload heavy computational lifting to a GPU without typing a single cloud provisioning command by Instructing Antigravity (or your agent of choice) to build a remote fine-tuning job. In this scenario, we ask our agent to use the Colab CLI to fine-tune google/gemma-3-1b-it on a Text-to-SQL dataset to make the model better at writing SQL queries.
The Antigravity prompt:
Use the Colab CLI (https://github.com/googlecolab/google-colab-cli) to fine-tune Gemma 3 1B using QLoRA. Provision a Colab T4 GPU instance, install the necessary ML packages (transformers, datasets, peft, trl, etc.), run my local ~finetune_run.py script remotely, download the resulting safetensors adapter, save the notebook log, and cleanup.
Antigravity executes:
$ colab new --gpu T4
$ colab install transformers datasets peft trl bitsandbytes accelerate
$ colab exec -f finetune_run.py
$ colab log --output gemma_finetune_log.ipynb
$ colab stop
Shell
Antigravity also uses the "colab download" command to download the adapter model, adapter config, tokenizer config, and tokenizer, which can be used to load and run your fine-tuned model locally. Now you have a remotely fine-tuned model ready to serve from your local device!
Try it out now
The Colab CLI makes powerful Colab compute accessible, programmable, and agent-ready. It is lightweight and easily accessible to any terminal-based AI agent. To start using the Colab CLI yourself, head over to the Google Colab CLI GitHub repository for setup instructions.
We are excited to see how this accelerates your development process and look forward to seeing what you and your agents build!