# Kaggle 实测 Qwen-Image-2.1 笔记本（已实测，2026-11-12）

## 实测结果（2026-11-12，笔记本 Qwen-Image-2.1 Kaggle T4 test，草稿）
- 环境：torch 2.11.0+cu130，diffusers 0.42.1，2× Tesla T4（各 15360MiB，驱动 580.178.04，CUDA 13.0）；主盘可用 967GB（/kaggle/working 20GB 只是持久目录，权重走主盘 HF 缓存）。
- 加载：下载 28.9GB（约 492MB/s），加载 163 秒，23 个文件。
- 生成：1024×1024、30 步、种子 42，**1060 秒（17.7 分钟，约 32 秒/步）**，峰值显存 11.00GB；四要素（雾山、湖、湖边小木屋、柔和晨光）全对。
- 对比 Colab 同参数：38.5 分钟（约 77 秒/步），峰值显存同样 11.00GB——**Kaggle 快约 2.2 倍**。
- 额度：每周 GPU 30 小时；每次新会话重下 28.9GB 权重。

## 笔记本设置
- 新建 Notebook，Accelerator 选 **GPU T4 x2**，Internet 选 **On**（下权重用）。
- 额度：每周约 30 小时 GPU，T4 x2 计 1 小时/小时；单次最长 12 小时。

## Cell 0：环境＋磁盘检查
```python
!nvidia-smi
!df -h
import torch
print("torch", torch.__version__, "cuda:", torch.cuda.is_available())
```
注意：`torch.cuda.get_device_count()` 在此环境不存在，别写进检查行（2026-11-12 第一版因此报错停过一次）。

## Cell 1：装依赖
```python
!pip install -q -U diffusers transformers accelerate
import torch, diffusers
print(torch.__version__, diffusers.__version__)
print("cuda:", torch.cuda.is_available(), torch.cuda.get_device_name(0) if torch.cuda.is_available() else "-")
```

## Cell 2：加载 Qwen-Image-2.1
```python
from diffusers import QwenImage21Pipeline
import torch

# 7B DiT，bf16；权重下载约 28.9GB（不是 14GB），走主盘 HF 缓存
pipe = QwenImage21Pipeline.from_pretrained("Qwen/Qwen-Image-2.1", torch_dtype=torch.bfloat16)
pipe.enable_sequential_cpu_offload()
print("loaded")
```
注意：`QwenImage21Pipeline` 没有 `enable_vae_tiling()`（加了报 AttributeError）；普通 `enable_model_cpu_offload()` 在 T4 上会 OOM，必须用顺序 offload（Colab 实测教训）。

## Cell 3：文生图实测
```python
prompt = "A serene Chinese ink wash landscape, misty mountains, a small wooden cabin by a lake, soft morning light"
image = pipe(
    prompt,
    width=1024, height=1024,
    num_inference_steps=30,
    generator=torch.Generator("cuda").manual_seed(42),
).images[0]
image.save("/kaggle/working/qwen_image_21_kaggle.png")
image
```
验收：出图、内容与提示词一致、记下耗时与显存占用。

## 守则
- Qwen-Image-2.1 走研究许可证，仅限非商用，个人测试没问题。
- 成果及时从 /kaggle/working 下载，会话结束即丢。
- 敏感内容不进；Kaggle 规则禁拿笔记本当服务器、禁挖矿。
