Cosmos3 action policy improvements (#6460)
Signed-off-by: Maciej Bala <mbala@nvidia.com> Signed-off-by: MaciejBalaNV <mbala@nvidia.com> Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
1 parent
c8bef008eb
commit
05ab509269
21 files changed
+863
-105
No files matched your search
@@ -3,6 +3,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import sys
|
||||
import types
|
||||
from dataclasses import dataclass
|
||||
@@ -21,6 +22,20 @@ from vllm_omni.experimental.world_models.session_state import SessionStateManage
|
||||
pytestmark = [pytest.mark.core_model, pytest.mark.cpu, pytest.mark.diffusion]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("alias", "canonical_name"),
|
||||
[
|
||||
("galbot", "embodiment_b"),
|
||||
("agibot_gear_gripper", "embodiment_c_gripper"),
|
||||
("agibot_gear_gripper_ext", "embodiment_c_gripper_ext"),
|
||||
],
|
||||
)
|
||||
def test_action_domain_table_preserves_legacy_aliases(alias: str, canonical_name: str) -> None:
|
||||
from vllm_omni.diffusion.models.cosmos3.action import resolve_domain_id
|
||||
|
||||
assert resolve_domain_id(domain_name=alias) == resolve_domain_id(domain_name=canonical_name)
|
||||
|
||||
|
||||
def test_pipeline_declares_layerwise_offload_components() -> None:
|
||||
from vllm_omni.diffusion.models.cosmos3.pipeline_cosmos3 import Cosmos3OmniDiffusersPipeline
|
||||
|
||||
@@ -479,6 +494,69 @@ def test_forward_threads_request_id_to_robolab(make_cosmos3_pipeline) -> None:
|
||||
assert captured["session_id"] == "robolab-request-7"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("format_prompt_as_json", [False, True])
|
||||
def test_robolab_input_builder_threads_prompt_format_and_uses_wam(
|
||||
make_cosmos3_pipeline,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
format_prompt_as_json: bool,
|
||||
) -> None:
|
||||
from vllm_omni.diffusion.models.cosmos3 import pipeline_cosmos3
|
||||
|
||||
pipeline = make_cosmos3_pipeline()
|
||||
pipeline.transformer = StubCosmos3Transformer(action_gen=True, action_dim=64)
|
||||
captured: dict[str, Any] = {}
|
||||
|
||||
def fake_transform(sample, resolution):
|
||||
captured["sample_mode"] = sample["mode"]
|
||||
captured["resolution"] = resolution
|
||||
sample["sequence_plan"] = SimpleNamespace(
|
||||
condition_frame_indexes_action=[0],
|
||||
action_start_frame_offset=1,
|
||||
)
|
||||
sample["raw_action_dim"] = torch.tensor(8)
|
||||
sample["image_size"] = torch.tensor([16, 16, 16, 16])
|
||||
if format_prompt_as_json:
|
||||
sample["ai_caption"] = {"actions": {"instruction": sample["ai_caption"]}}
|
||||
return sample
|
||||
|
||||
def fake_get_transform(*, format_prompt_as_json: bool):
|
||||
captured["format_prompt_as_json"] = format_prompt_as_json
|
||||
return fake_transform
|
||||
|
||||
pipeline._get_robolab_transform = fake_get_transform
|
||||
monkeypatch.setattr(pipeline_cosmos3, "get_robolab_domain_id", lambda name: 8)
|
||||
obs = {
|
||||
"prompt": "Pick up the cube.",
|
||||
"observation/image": np.zeros((16, 16, 3), dtype=np.uint8),
|
||||
"observation/joint_position": np.zeros(7, dtype=np.float32),
|
||||
"observation/gripper_position": np.zeros(1, dtype=np.float32),
|
||||
}
|
||||
sampling_params = make_sampling_params(
|
||||
extra_args={
|
||||
"robot_obs": obs,
|
||||
"action_chunk_size": 2,
|
||||
"image_height": 16,
|
||||
"image_width": 16,
|
||||
"format_prompt_as_json": format_prompt_as_json,
|
||||
}
|
||||
)
|
||||
|
||||
inputs = pipeline._build_robolab_policy_inputs(sampling_params, request_id="request-1")
|
||||
|
||||
assert inputs is not None
|
||||
assert captured == {
|
||||
"sample_mode": "wam",
|
||||
"resolution": "480",
|
||||
"format_prompt_as_json": format_prompt_as_json,
|
||||
}
|
||||
assert inputs.domain_id == 8
|
||||
assert inputs.raw_action_dim == 8
|
||||
if format_prompt_as_json:
|
||||
assert json.loads(inputs.prompt) == {"actions": {"instruction": "Pick up the cube."}}
|
||||
else:
|
||||
assert inputs.prompt == "Pick up the cube."
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("prompt", "sampling_params", "message"),
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user