Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Preserve Git patch bytes, including whitespace in diff context.
/model_examples/Cosmos3/*.patch -text -whitespace
*.sh text eol=lf
42 changes: 42 additions & 0 deletions THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Third-Party Notices and Provenance

This file records the provenance of source code distributed in TurboPhysAI. The root [BSD-3-Clause License](LICENSE) applies to Hygon-authored material only. A source file derived from an upstream work remains subject to its upstream license and notices.
Expand Down Expand Up @@ -146,3 +146,45 @@
## Hygon modification notice

Where Apache-2.0 source code was modified, the source file retains the upstream copyright and license notice, then adds Hygon copyright and `Modified by Hygon.`. The notice does not change the upstream license.

## Cosmos3 (OpenMDW-1.1)

- Repository: <https://github.com/NVIDIA/cosmos-framework>
- Fixed commit: `9726697a83315540c6885baefd2fe353d9c74920`
- License: OpenMDW-1.1

`model_examples/Cosmos3/cosmos-framework.patch` contains modifications derived from NVIDIA Cosmos Framework. Cosmos-derived material retains OpenMDW-1.1 and applicable source-file notices.

| Local patch | Upstream file / Added file | Change type |
| --- | --- | --- |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/callbacks/device_monitor.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/checkpoint/dcp.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/checkpoint/load_only.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/configs/toml_config/sft_config.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/data/generator/action/datasets/cosmos3_action_lerobot.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/data/generator/augmentors/interleaved_video_parsing.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/data/generator/augmentors/video_parsing.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/data/generator/joint_dataloader.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/data/generator/sequence_packing/runtime.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/attention/flash2/functions.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/attention/utils/__init__.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/mot/attention.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/mot/cosmos3_vfm_network.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/omni_mot_model.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/parallelize_vlm.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/reasoner/qwen3_vl/__init__.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/reasoner/qwen3_vl/qwen3_vl.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/reasoner/qwen3_vl/utils.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/fused_ops/__init__.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/fused_ops/_concat_layout.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/fused_ops/_hipdnn.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/fused_ops/concat_conv_bias.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/fused_ops/conv_bias.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/model/generator/tokenizers/wan2pt2_vae_4x16x16.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/scripts/convert_model_to_dcp.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/distributed.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/fsdp_ordered_comm.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/memory_format.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/memory_format_test.py` | Added |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/misc.py` | Modified |
| `model_examples/Cosmos3/cosmos-framework.patch` | `cosmos_framework/utils/video_decode.py` | Added |
3 changes: 3 additions & 0 deletions docs/zh/models/support_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

TurboPhysAI 不强制模型仓库停留在优化接入基线([可以在优化接入基线之外的模型版本上使用吗?](../faq.md#可以在优化接入基线之外的模型版本上使用吗))。

Cosmos3 通过独立源码补丁提供支持,需使用指定基线应用补丁,再通过 Cosmos 原生训练入口运行,具体步骤见模型使用说明。

## 已支持模型

| 模型 | Method | Backbone | 优化接入基线 | 使用说明 |
| :-------: | :------------: | :------: | :------------------------------------------: | :---------------------------------------------------: |
| BEVFormer | BEVFormer-base | R101-DCN | `66b65f3a1f58caf0507cb2a971b9c0e7f842376c` | [BEVFormer](../../../model_examples/BEVFormer/README.md) |
| BEVFusion | BEVFusion | — | `326653dc06e0938edf1aae7d01efcd158ba83de5` | [BEVFusion](../../../model_examples/BEVFusion/README.md) |
| Cosmos3 | Generator / Action Policy / Reasoner | — | `9726697a83315540c6885baefd2fe353d9c74920` | [Cosmos3](../../../model_examples/Cosmos3/README.md) |

**自动驾驶**、**具身智能**和**世界模型**等方向的模型适配工作持续推进中,请关注后续更新。
207 changes: 207 additions & 0 deletions model_examples/Cosmos3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# Cosmos3 运行指南

在 `cosmos-framework` 根目录应用 Cosmos3 补丁,再直接启动训练。以下示例使用 8 张 HCU,训练 70 步。

## 环境准备

### 拉取镜像及创建容器
```
docker pull harbor.sourcefind.cn:5443/hcu/admin/base/custom:dit-vla-wm-base-ubuntu22.04-dtk26.04-torch2.10-py3.10-20260929

docker run -it --network=host --name=cosmos_hygon --privileged --device=/dev/kfd --device=/dev/dri --ipc=host --shm-size=512G --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -u root --ulimit stack=-1:-1 --ulimit memlock=-1:-1 -v /opt/hyhal:/opt/hyhal:ro harbor.sourcefind.cn:5443/hcu/admin/base/custom:dit-vla-wm-base-ubuntu22.04-dtk26.04-torch2.10-py3.10-20260929
```
### 准备代码
```bash
git clone --branch feature/cosmos3-patch https://github.com/iMountTai/TurboPhysAI.git
cd TurboPhysAI
cd ..
git clone https://github.com/NVIDIA/cosmos-framework.git
cd cosmos-framework
git checkout 9726697a
```

### 应用补丁

在 Cosmos 仓库根目录应用补丁;以下假设 TurboPhysAI 和 cosmos-framework 是同级相邻目录:

```bash
git apply ../TurboPhysAI/model_examples/Cosmos3/cosmos-framework.patch
```

如需撤销补丁:

```bash
git apply -R ../TurboPhysAI/model_examples/Cosmos3/cosmos-framework.patch
```

### 安装训练依赖
```
cd /data/TurboPhysAI
pip install -r model_examples/Cosmos3/requirements.txt
pip install lerobot --no-deps
```

## 数据与模型权重

按训练任务准备以下资产,路径通过后面的环境变量设置。

| 任务 | 数据 | 模型权重 |
| --- | --- | --- |
| Generator Nano | BridgeData2 的 `sft_dataset_bridge` | Cosmos3-Nano DCP、Wan2.2 VAE、Cosmos3-Nano processor/tokenizer |
| Action Policy | DROID LeRobot 数据集 | Cosmos3-Nano DCP、Wan2.2 VAE、Qwen3-VL-8B tokenizer 缓存 |
| Reasoner | VideoPhy2 或 LLaVA-OV 配方对应数据 | Qwen3-VL 模型目录、Cosmos3-Nano-VLM safetensors |


```bash
cd /data
wget http://42.228.13.241:18000/docker-images/tencent/Cosmos3/BridgeData2-Subset-Synthetic-Captions.zip
Comment thread
iMountTai marked this conversation as resolved.
unzip BridgeData2-Subset-Synthetic-Captions.zip

wget http://42.228.13.241:18000/docker-images/tencent/Cosmos3/videophysics_official.tar.gz
tar -xzf videophysics_official.tar.gz -C /data/

wget http://42.228.13.241:18000/docker-images/tencent/Cosmos3/Cosmos3-DROID-perf64.tar.gz
tar -xzf Cosmos3-DROID-perf64.tar.gz -C /data/

wget http://42.228.13.241:18000/docker-images/tencent/Cosmos3/Qwen3-VL-8B-Instruct-tokenizer-cache.tar.gz
tar -xzf Qwen3-VL-8B-Instruct-tokenizer-cache.tar.gz -C /data/
```

DROID perf64 子集使用 `/data/Cosmos3-DROID-perf64/keep_ranges_perf64.json` 过滤文件。Tokenizer 缓存解压到 `/data/hf-cache`,不包含 Qwen 模型权重。

将 Cosmos3-Nano HF 权重转换为 DCP 时,在 Cosmos 仓库根目录设置 `WAN_VAE_PATH` 和 `BASE_CHECKPOINT_PATH`,然后执行:

```bash
WAN_VAE_PATH=$WAN_VAE_PATH HF_HUB_OFFLINE=1 \
python -m cosmos_framework.scripts.convert_model_to_dcp \
-i /path/to/Cosmos3-Nano -o $BASE_CHECKPOINT_PATH
```

上游转换脚本会读取 VAE/processor;离线环境需预先准备 Hugging Face 缓存。

## 启动训练

所有命令均在 `cosmos-framework` 根目录执行,训练场景由 `--sft-toml` 选择。
运行环境由 Shell 明确设置,无需 Turbo runtime 配置:

```bash
export PYTHONPATH="$PWD"
export HIP_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export HF_HUB_OFFLINE=1 OMP_NUM_THREADS=1
export MIOPEN_FIND_MODE=1 PYTORCH_MIOPEN_SUGGEST_NDHWC=1
export TORCH_NCCL_HIGH_PRIORITY=1
```

### Generator Nano

设置数据与权重路径后运行:

```bash
export HIP_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export DATASET_PATH=/data/BridgeData2-Subset-Synthetic-Captions/sft_dataset_bridge
export BASE_CHECKPOINT_PATH=path/to/Cosmos3-Nano-DCP
export WAN_VAE_PATH=path/to/Wan2.2_VAE.pth
export LOCAL_PROCESSOR_DIR=path/to/Cosmos3-Nano
export IMAGINAIRE_OUTPUT_ROOT=./outputs/hcu_training

torchrun --nproc-per-node=8 --master_port=29712 \
-m cosmos_framework.scripts.train \
--sft-toml=examples/toml/sft_config/vision_sft_nano.toml \
-- \
job.name=generator_vision_sft_nano_hcu_perf_8card \
job.wandb_mode=offline \
model.config.vlm_config.tokenizer.pretrained_model_name=$LOCAL_PROCESSOR_DIR \
dataloader_train.dataloader.prefetch_factor=16 \
trainer.max_iter=70 \
checkpoint.save_iter=1000 \
trainer.callbacks.compile_tokenizer.enabled=true \
trainer.callbacks.compile_tokenizer.compile_after_iterations=3 \
'trainer.callbacks.compile_tokenizer.warmup_resolutions=["256"]'
```

### Action Policy(DROID)

```bash
export HF_HOME=/data/cosmos-test/hf-cache
export BASE_CHECKPOINT_PATH=path/to/Cosmos3-Nano-DCP
export WAN_VAE_PATH=path/to/Wan2.2_VAE.pth
export LOCAL_PROCESSOR_DIR=path/to/Cosmos3-Nano
export DROID_ROOT=/data/Cosmos/datasets/droid_plus_lerobot_640x360_20260412
export KEEP_RANGES_PATH=/data/Cosmos/datasets/Cosmos3-DROID-perf64/keep_ranges_perf64.json
export IMAGINAIRE_OUTPUT_ROOT=./outputs/action_policy
export TORCHINDUCTOR_WORKER_START=spawn TORCHINDUCTOR_COMPILE_THREADS=4
export OMP_NUM_THREADS=4

torchrun --nproc_per_node=8 --master_port=29716 \
-m cosmos_framework.scripts.train \
--sft-toml=examples/toml/sft_config/action_policy_droid_nano.toml -- \
job.wandb_mode=disabled job.name=action_policy_sft_nano_hcu_perf_8card_ops \
model.config.vlm_config.tokenizer.pretrained_model_name=$LOCAL_PROCESSOR_DIR \
model.config.parallelism.data_parallel_shard_degree=8 \
model.config.parallelism.data_parallel_replicate_degree=1 \
dataloader_train.max_samples_per_batch=8 \
dataloader_train.dataloader.batch_size=8 \
dataloader_train.dataloader.num_workers=1 \
+dataloader_train.dataloader.multiprocessing_context=spawn \
dataloader_train.dataloader.prefetch_factor=4 \
dataloader_train.dataloader.datasets.droid.dataset.mode=wam \
dataloader_train.dataloader.datasets.droid.dataset.video_backend=pyav \
dataloader_train.dataloader.datasets.droid.dataset.use_filter_dict=true \
dataloader_train.dataloader.datasets.droid.dataset.filter_dict_path="$KEEP_RANGES_PATH" \
model.config.rectified_flow_training_config.loss_scale=10.0 \
trainer.seed=42 trainer.max_iter=70 \
model.config.compile.enabled=true model.config.compile.compile_dynamic=true \
trainer.callbacks.compile_tokenizer.enabled=false \
checkpoint.save_iter=1000 checkpoint.dcp_async_mode_enabled=false
```

本例使用 DROID perf64 子集及对应过滤文件,`MIOPEN_FIND_MODE=1` 由前面的 Shell 设置提供。

一次性性能运行如需关闭 checkpoint 写入,追加 `checkpoint.type._target_=cosmos_framework.checkpoint.load_only.LoadOnlyDistributedCheckpointer`;默认保留正常保存行为。

### Reasoner VideoPhy2

```bash
export VIDEOPHYSICS_ROOT=/data/videophysics_official
export VLM_MODEL_NAME=/path/to/Qwen3-VL-8B-Instruct
export VLM_SAFETENSORS_PATH=/path/to/Cosmos3-Nano-VLM
export IMAGINAIRE_OUTPUT_ROOT=./outputs/reasoner

torchrun --nproc_per_node=8 --master_port=29711 \
-m cosmos_framework.scripts.train \
--sft-toml=examples/toml/sft_config/videophy2_sft_nano.toml -- \
job.wandb_mode=disabled job.name=reasoner_videophy2_nano_hcu \
model.config.policy.backbone.model_name="$VLM_MODEL_NAME" \
model.config.policy.backbone.safetensors_path="$VLM_SAFETENSORS_PATH" \
model.config.parallelism.data_parallel_shard_degree=8 \
trainer.seed=42 trainer.max_iter=70 scheduler.cycle_lengths=[70] \
trainer.callbacks.log_tensor_shape.num_log=-1 checkpoint.save_iter=1000 \
model.config.compile.enabled=true model.config.compile.compile_dynamic=true \
model.config.activation_checkpointing.mode=none \
model.config.parallelism.fsdp_layers_per_group=8
```

### Reasoner LLaVA-OV

沿用上面的 VLM 路径。

```bash
HF_HUB_OFFLINE=0 torchrun --nproc_per_node=8 --master_port=29715 \
-m cosmos_framework.scripts.train \
--sft-toml=examples/toml/sft_config/llava_ov.toml -- \
job.wandb_mode=disabled job.name=reasoner_llava_ov_hcu \
model.config.policy.backbone.model_name="$VLM_MODEL_NAME" \
model.config.policy.backbone.safetensors_path="$VLM_SAFETENSORS_PATH" \
model.config.parallelism.data_parallel_shard_degree=8 data_setting.max_tokens=16000 \
trainer.seed=42 trainer.max_iter=70 scheduler.cycle_lengths=[70] \
trainer.callbacks.log_tensor_shape.num_log=-1 \
checkpoint.save_iter=1000 checkpoint.dcp_async_mode_enabled=false
```

## 运行说明

- 运行环境以 Shell 中的设置为准,日志与训练产物由 `IMAGINAIRE_OUTPUT_ROOT` 指定。
- 修改卡数时,同步调整 `HIP_VISIBLE_DEVICES`、`--nproc_per_node` 和 `data_parallel_shard_degree`。
- 调整 Reasoner 训练步数时,同步修改 `trainer.max_iter` 和 `scheduler.cycle_lengths`。
- 单项优化通过模型的环境变量或训练配置控制。
- 也可直接使用 patch 中的 `examples/launch_sft_*_hcu.sh`,按各脚本说明设置资产与运行参数。
Loading