Spaces:
Running
Running
Upload 28 files
Browse files- aegis-reason/aegis-reason/.gitattributes +4 -0
- aegis-reason/aegis-reason/.gitignore +12 -0
- aegis-reason/aegis-reason/Dockerfile +154 -0
- aegis-reason/aegis-reason/LICENSE +189 -0
- aegis-reason/aegis-reason/README.md +192 -0
- aegis-reason/aegis-reason/aegis_convert_llava.py +224 -0
- aegis-reason/aegis-reason/aegis_data_generator.py +434 -0
- aegis-reason/aegis-reason/aegis_dataloader.py +102 -0
- aegis-reason/aegis-reason/aegis_grpo_reward.py +279 -0
- aegis-reason/aegis-reason/aegis_inference.py +344 -0
- aegis-reason/aegis-reason/aegis_render_engine.py +946 -0
- aegis-reason/aegis-reason/aegis_varp.py +536 -0
- aegis-reason/aegis-reason/configs/aegis_grpo.toml +102 -0
- aegis-reason/aegis-reason/configs/aegis_sft.toml +112 -0
- aegis-reason/aegis-reason/demo/aegis_dashboard.jsx +291 -0
- aegis-reason/aegis-reason/demo/aegis_scenario_demo.gif +0 -0
- aegis-reason/aegis-reason/docs/aegis_cookbook_recipe.md +300 -0
- aegis-reason/aegis-reason/docs/benchmark_analysis.json +69 -0
- aegis-reason/aegis-reason/docs/hf_dataset_card.md +143 -0
- aegis-reason/aegis-reason/maelstrom_core.py +664 -0
- aegis-reason/aegis-reason/requirements.txt +9 -0
- aegis-reason/aegis-reason/samples/egocentric_sample.png +0 -0
- aegis-reason/aegis-reason/samples/sample_chain.json +11 -0
- aegis-reason/aegis-reason/samples/topdown_step0.png +0 -0
- aegis-reason/aegis-reason/samples/topdown_step4.png +0 -0
- aegis-reason/aegis-reason/scripts/aegis_e2e_test.py +393 -0
- aegis-reason/aegis-reason/scripts/nebius_train.sh +311 -0
- aegis-reason/aegis-reason/scripts/push_to_hub.py +135 -0
aegis-reason/aegis-reason/.gitattributes
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.gif filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
aegis-reason/aegis-reason/.gitignore
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
*.pyo
|
| 4 |
+
.env
|
| 5 |
+
aegis_dataset/
|
| 6 |
+
aegis_llava/
|
| 7 |
+
*.egg-info/
|
| 8 |
+
dist/
|
| 9 |
+
build/
|
| 10 |
+
.venv/
|
| 11 |
+
wandb/
|
| 12 |
+
outputs/
|
aegis-reason/aegis-reason/Dockerfile
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ============================================================
|
| 2 |
+
# AEGIS-Reason — Full Reproducibility Container
|
| 3 |
+
# ============================================================
|
| 4 |
+
# Two-stage build:
|
| 5 |
+
# Stage 1: Data generation (CPU-only, any machine)
|
| 6 |
+
# Stage 2: Training (requires NVIDIA GPU runtime)
|
| 7 |
+
#
|
| 8 |
+
# Usage:
|
| 9 |
+
# # Build
|
| 10 |
+
# docker build -t aegis-reason .
|
| 11 |
+
#
|
| 12 |
+
# # Generate dataset (CPU)
|
| 13 |
+
# docker run --rm -v $(pwd)/data:/data aegis-reason generate
|
| 14 |
+
#
|
| 15 |
+
# # Train SFT (GPU)
|
| 16 |
+
# docker run --rm --gpus all \
|
| 17 |
+
# -e HF_TOKEN=$HF_TOKEN \
|
| 18 |
+
# -e WANDB_API_KEY=$WANDB_API_KEY \
|
| 19 |
+
# -v $(pwd)/data:/data \
|
| 20 |
+
# aegis-reason train-sft
|
| 21 |
+
#
|
| 22 |
+
# # Train GRPO (GPU)
|
| 23 |
+
# docker run --rm --gpus all \
|
| 24 |
+
# -e HF_TOKEN=$HF_TOKEN \
|
| 25 |
+
# -v $(pwd)/data:/data \
|
| 26 |
+
# aegis-reason train-grpo
|
| 27 |
+
#
|
| 28 |
+
# # Evaluate
|
| 29 |
+
# docker run --rm --gpus all \
|
| 30 |
+
# -v $(pwd)/data:/data \
|
| 31 |
+
# aegis-reason evaluate --checkpoint /data/outputs/aegis_sft_2b/checkpoints/step_250/policy
|
| 32 |
+
# ============================================================
|
| 33 |
+
|
| 34 |
+
FROM nvidia/cuda:12.4.1-devel-ubuntu22.04 AS base
|
| 35 |
+
|
| 36 |
+
# System deps
|
| 37 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 38 |
+
python3 python3-pip python3-venv git wget unzip redis-server \
|
| 39 |
+
libgl1-mesa-glx libglib2.0-0 \
|
| 40 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 41 |
+
|
| 42 |
+
# Python environment
|
| 43 |
+
RUN python3 -m pip install --upgrade pip setuptools wheel
|
| 44 |
+
|
| 45 |
+
# Core Python deps (data generation — no GPU needed)
|
| 46 |
+
RUN pip3 install --no-cache-dir \
|
| 47 |
+
numpy>=1.24 \
|
| 48 |
+
Pillow>=10.0 \
|
| 49 |
+
matplotlib>=3.7
|
| 50 |
+
|
| 51 |
+
WORKDIR /app
|
| 52 |
+
|
| 53 |
+
# Copy AEGIS source files
|
| 54 |
+
COPY maelstrom_core.py .
|
| 55 |
+
COPY aegis_render_engine.py .
|
| 56 |
+
COPY aegis_data_generator.py .
|
| 57 |
+
COPY aegis_convert_llava.py .
|
| 58 |
+
COPY aegis_dataloader.py .
|
| 59 |
+
COPY aegis_grpo_reward.py .
|
| 60 |
+
COPY aegis_inference.py .
|
| 61 |
+
COPY aegis_varp.py .
|
| 62 |
+
COPY aegis_sft.toml .
|
| 63 |
+
COPY aegis_grpo.toml .
|
| 64 |
+
COPY nebius_train.sh .
|
| 65 |
+
COPY aegis_e2e_test.py .
|
| 66 |
+
|
| 67 |
+
RUN chmod +x nebius_train.sh
|
| 68 |
+
|
| 69 |
+
# ============================================================
|
| 70 |
+
# Entrypoint script
|
| 71 |
+
# ============================================================
|
| 72 |
+
COPY <<'ENTRYPOINT' /app/entrypoint.sh
|
| 73 |
+
#!/bin/bash
|
| 74 |
+
set -euo pipefail
|
| 75 |
+
|
| 76 |
+
case "${1:-help}" in
|
| 77 |
+
generate)
|
| 78 |
+
echo "=== AEGIS: Generating dataset ==="
|
| 79 |
+
python3 aegis_data_generator.py \
|
| 80 |
+
--seeds "${AEGIS_SEEDS:-40}" \
|
| 81 |
+
--output "${DATA_DIR:-/data}/aegis_dataset"
|
| 82 |
+
python3 aegis_convert_llava.py \
|
| 83 |
+
--input "${DATA_DIR:-/data}/aegis_dataset/sft_data.jsonl" \
|
| 84 |
+
--output "${DATA_DIR:-/data}/aegis_llava" \
|
| 85 |
+
--views both
|
| 86 |
+
echo "=== Dataset generated ==="
|
| 87 |
+
;;
|
| 88 |
+
|
| 89 |
+
train-sft)
|
| 90 |
+
echo "=== AEGIS: SFT Training ==="
|
| 91 |
+
DATA_DIR="${DATA_DIR:-/data}"
|
| 92 |
+
# Clone cosmos-reason2 if needed
|
| 93 |
+
if [ ! -d "$DATA_DIR/cosmos-reason2" ]; then
|
| 94 |
+
git clone https://github.com/nvidia-cosmos/cosmos-reason2.git "$DATA_DIR/cosmos-reason2"
|
| 95 |
+
fi
|
| 96 |
+
cd "$DATA_DIR/cosmos-reason2/examples/cosmos_rl"
|
| 97 |
+
[ -d ".venv" ] || (python3 -m venv .venv && source .venv/bin/activate && pip install -e ".[all]")
|
| 98 |
+
source .venv/bin/activate
|
| 99 |
+
|
| 100 |
+
# Patch config with actual data paths
|
| 101 |
+
sed "s|/data/aegis|$DATA_DIR|g" /app/aegis_sft.toml > /tmp/aegis_sft.toml
|
| 102 |
+
cp /app/aegis_dataloader.py /tmp/
|
| 103 |
+
|
| 104 |
+
cosmos-rl --config /tmp/aegis_sft.toml /tmp/aegis_dataloader.py
|
| 105 |
+
echo "=== SFT Training complete ==="
|
| 106 |
+
;;
|
| 107 |
+
|
| 108 |
+
train-grpo)
|
| 109 |
+
echo "=== AEGIS: GRPO RL Training ==="
|
| 110 |
+
DATA_DIR="${DATA_DIR:-/data}"
|
| 111 |
+
cd "$DATA_DIR/cosmos-reason2/examples/cosmos_rl"
|
| 112 |
+
source .venv/bin/activate
|
| 113 |
+
|
| 114 |
+
sed "s|/data/aegis|$DATA_DIR|g" /app/aegis_grpo.toml > /tmp/aegis_grpo.toml
|
| 115 |
+
cp /app/aegis_grpo_reward.py /tmp/
|
| 116 |
+
|
| 117 |
+
cosmos-rl --config /tmp/aegis_grpo.toml /tmp/aegis_grpo_reward.py
|
| 118 |
+
echo "=== GRPO Training complete ==="
|
| 119 |
+
;;
|
| 120 |
+
|
| 121 |
+
evaluate)
|
| 122 |
+
echo "=== AEGIS: Evaluation ==="
|
| 123 |
+
shift
|
| 124 |
+
python3 /app/aegis_inference.py "$@"
|
| 125 |
+
;;
|
| 126 |
+
|
| 127 |
+
test)
|
| 128 |
+
echo "=== AEGIS: End-to-End Validation ==="
|
| 129 |
+
python3 /app/aegis_e2e_test.py
|
| 130 |
+
;;
|
| 131 |
+
|
| 132 |
+
help|*)
|
| 133 |
+
echo "AEGIS-Reason Container"
|
| 134 |
+
echo ""
|
| 135 |
+
echo "Commands:"
|
| 136 |
+
echo " generate Generate training dataset (CPU-only)"
|
| 137 |
+
echo " train-sft Run SFT training (requires GPU)"
|
| 138 |
+
echo " train-grpo Run GRPO RL training (requires GPU)"
|
| 139 |
+
echo " evaluate Run inference + VARP evaluation"
|
| 140 |
+
echo " test Run end-to-end validation (CPU)"
|
| 141 |
+
echo ""
|
| 142 |
+
echo "Environment variables:"
|
| 143 |
+
echo " HF_TOKEN HuggingFace token"
|
| 144 |
+
echo " WANDB_API_KEY Weights & Biases key"
|
| 145 |
+
echo " DATA_DIR Data directory (default: /data)"
|
| 146 |
+
echo " AEGIS_SEEDS Number of seeds for generation (default: 40)"
|
| 147 |
+
;;
|
| 148 |
+
esac
|
| 149 |
+
ENTRYPOINT
|
| 150 |
+
|
| 151 |
+
RUN chmod +x /app/entrypoint.sh
|
| 152 |
+
|
| 153 |
+
ENTRYPOINT ["/app/entrypoint.sh"]
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Apache License
|
| 2 |
+
Version 2.0, January 2004
|
| 3 |
+
http://www.apache.org/licenses/
|
| 4 |
+
|
| 5 |
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
| 6 |
+
|
| 7 |
+
1. Definitions.
|
| 8 |
+
|
| 9 |
+
"License" shall mean the terms and conditions for use, reproduction,
|
| 10 |
+
and distribution as defined by Sections 1 through 9 of this document.
|
| 11 |
+
|
| 12 |
+
"Licensor" shall mean the copyright owner or entity authorized by
|
| 13 |
+
the copyright owner that is granting the License.
|
| 14 |
+
|
| 15 |
+
"Legal Entity" shall mean the union of the acting entity and all
|
| 16 |
+
other entities that control, are controlled by, or are under common
|
| 17 |
+
control with that entity. For the purposes of this definition,
|
| 18 |
+
"control" means (i) the power, direct or indirect, to cause the
|
| 19 |
+
direction or management of such entity, whether by contract or
|
| 20 |
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
| 21 |
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
| 22 |
+
|
| 23 |
+
"You" (or "Your") shall mean an individual or Legal Entity
|
| 24 |
+
exercising permissions granted by this License.
|
| 25 |
+
|
| 26 |
+
"Source" form shall mean the preferred form for making modifications,
|
| 27 |
+
including but not limited to software source code, documentation
|
| 28 |
+
source, and configuration files.
|
| 29 |
+
|
| 30 |
+
"Object" form shall mean any form resulting from mechanical
|
| 31 |
+
transformation or translation of a Source form, including but
|
| 32 |
+
not limited to compiled object code, generated documentation,
|
| 33 |
+
and conversions to other media types.
|
| 34 |
+
|
| 35 |
+
"Work" shall mean the work of authorship, whether in Source or
|
| 36 |
+
Object form, made available under the License, as indicated by a
|
| 37 |
+
copyright notice that is included in or attached to the work.
|
| 38 |
+
|
| 39 |
+
"Derivative Works" shall mean any work, whether in Source or Object
|
| 40 |
+
form, that is based on (or derived from) the Work and for which the
|
| 41 |
+
editorial revisions, annotations, elaborations, or other modifications
|
| 42 |
+
represent, as a whole, an original work of authorship. For the purposes
|
| 43 |
+
of this License, Derivative Works shall not include works that remain
|
| 44 |
+
separable from, or merely link (or bind by name) to the interfaces of,
|
| 45 |
+
the Work and Derivative Works thereof.
|
| 46 |
+
|
| 47 |
+
"Contribution" shall mean any work of authorship, including
|
| 48 |
+
the original version of the Work and any modifications or additions
|
| 49 |
+
to that Work or Derivative Works thereof, that is intentionally
|
| 50 |
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
| 51 |
+
or by an individual or Legal Entity authorized to submit on behalf of
|
| 52 |
+
the copyright owner. For the purposes of this definition, "submitted"
|
| 53 |
+
means any form of electronic, verbal, or written communication sent
|
| 54 |
+
to the Licensor or its representatives, including but not limited to
|
| 55 |
+
communication on electronic mailing lists, source code control systems,
|
| 56 |
+
and issue tracking systems that are managed by, or on behalf of, the
|
| 57 |
+
Licensor for the purpose of discussing and improving the Work, but
|
| 58 |
+
excluding communication that is conspicuously marked or otherwise
|
| 59 |
+
designated in writing by the copyright owner as "Not a Contribution."
|
| 60 |
+
|
| 61 |
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
| 62 |
+
on behalf of whom a Contribution has been received by the Licensor and
|
| 63 |
+
subsequently incorporated within the Work.
|
| 64 |
+
|
| 65 |
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
| 66 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 67 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 68 |
+
copyright license to reproduce, prepare Derivative Works of,
|
| 69 |
+
publicly display, publicly perform, sublicense, and distribute the
|
| 70 |
+
Work and such Derivative Works in Source or Object form.
|
| 71 |
+
|
| 72 |
+
3. Grant of Patent License. Subject to the terms and conditions of
|
| 73 |
+
this License, each Contributor hereby grants to You a perpetual,
|
| 74 |
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
| 75 |
+
(except as stated in this section) patent license to make, have made,
|
| 76 |
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
| 77 |
+
where such license applies only to those patent claims licensable
|
| 78 |
+
by such Contributor that are necessarily infringed by their
|
| 79 |
+
Contribution(s) alone or by combination of their Contribution(s)
|
| 80 |
+
with the Work to which such Contribution(s) was submitted. If You
|
| 81 |
+
institute patent litigation against any entity (including a
|
| 82 |
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
| 83 |
+
or a Contribution incorporated within the Work constitutes direct
|
| 84 |
+
or contributory patent infringement, then any patent licenses
|
| 85 |
+
granted to You under this License for that Work shall terminate
|
| 86 |
+
as of the date such litigation is filed.
|
| 87 |
+
|
| 88 |
+
4. Redistribution. You may reproduce and distribute copies of the
|
| 89 |
+
Work or Derivative Works thereof in any medium, with or without
|
| 90 |
+
modifications, and in Source or Object form, provided that You
|
| 91 |
+
meet the following conditions:
|
| 92 |
+
|
| 93 |
+
(a) You must give any other recipients of the Work or
|
| 94 |
+
Derivative Works a copy of this License; and
|
| 95 |
+
|
| 96 |
+
(b) You must cause any modified files to carry prominent notices
|
| 97 |
+
stating that You changed the files; and
|
| 98 |
+
|
| 99 |
+
(c) You must retain, in the Source form of any Derivative Works
|
| 100 |
+
that You distribute, all copyright, patent, trademark, and
|
| 101 |
+
attribution notices from the Source form of the Work,
|
| 102 |
+
excluding those notices that do not pertain to any part of
|
| 103 |
+
the Derivative Works; and
|
| 104 |
+
|
| 105 |
+
(d) If the Work includes a "NOTICE" text file as part of its
|
| 106 |
+
distribution, then any Derivative Works that You distribute must
|
| 107 |
+
include a readable copy of the attribution notices contained
|
| 108 |
+
within such NOTICE file, excluding any notices that do not
|
| 109 |
+
pertain to any part of the Derivative Works, in at least one
|
| 110 |
+
of the following places: within a NOTICE text file distributed
|
| 111 |
+
as part of the Derivative Works; within the Source form or
|
| 112 |
+
documentation, if provided along with the Derivative Works; or,
|
| 113 |
+
within a display generated by the Derivative Works, if and
|
| 114 |
+
wherever such third-party notices normally appear. The contents
|
| 115 |
+
of the NOTICE file are for informational purposes only and
|
| 116 |
+
do not modify the License. You may add Your own attribution
|
| 117 |
+
notices within Derivative Works that You distribute, alongside
|
| 118 |
+
or as an addendum to the NOTICE text from the Work, provided
|
| 119 |
+
that such additional attribution notices cannot be construed
|
| 120 |
+
as modifying the License.
|
| 121 |
+
|
| 122 |
+
You may add Your own copyright statement to Your modifications and
|
| 123 |
+
may provide additional or different license terms and conditions
|
| 124 |
+
for use, reproduction, or distribution of Your modifications, or
|
| 125 |
+
for any such Derivative Works as a whole, provided Your use,
|
| 126 |
+
reproduction, and distribution of the Work otherwise complies with
|
| 127 |
+
the conditions stated in this License.
|
| 128 |
+
|
| 129 |
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
| 130 |
+
any Contribution intentionally submitted for inclusion in the Work
|
| 131 |
+
by You to the Licensor shall be under the terms and conditions of
|
| 132 |
+
this License, without any additional terms or conditions.
|
| 133 |
+
Notwithstanding the above, nothing herein shall supersede or modify
|
| 134 |
+
the terms of any separate license agreement you may have executed
|
| 135 |
+
with Licensor regarding such Contributions.
|
| 136 |
+
|
| 137 |
+
6. Trademarks. This License does not grant permission to use the trade
|
| 138 |
+
names, trademarks, service marks, or product names of the Licensor,
|
| 139 |
+
except as required for reasonable and customary use in describing the
|
| 140 |
+
origin of the Work and reproducing the content of the NOTICE file.
|
| 141 |
+
|
| 142 |
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
| 143 |
+
agreed to in writing, Licensor provides the Work (and each
|
| 144 |
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
| 145 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
| 146 |
+
implied, including, without limitation, any warranties or conditions
|
| 147 |
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
| 148 |
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
| 149 |
+
appropriateness of using or redistributing the Work and assume any
|
| 150 |
+
risks associated with Your exercise of permissions under this License.
|
| 151 |
+
|
| 152 |
+
8. Limitation of Liability. In no event and under no legal theory,
|
| 153 |
+
whether in tort (including negligence), contract, or otherwise,
|
| 154 |
+
unless required by applicable law (such as deliberate and grossly
|
| 155 |
+
negligent acts) or agreed to in writing, shall any Contributor be
|
| 156 |
+
liable to You for damages, including any direct, indirect, special,
|
| 157 |
+
incidental, or consequential damages of any character arising as a
|
| 158 |
+
result of this License or out of the use or inability to use the
|
| 159 |
+
Work (including but not limited to damages for loss of goodwill,
|
| 160 |
+
work stoppage, computer failure or malfunction, or any and all
|
| 161 |
+
other commercial damages or losses), even if such Contributor
|
| 162 |
+
has been advised of the possibility of such damages.
|
| 163 |
+
|
| 164 |
+
9. Accepting Warranty or Additional Liability. While redistributing
|
| 165 |
+
the Work or Derivative Works thereof, You may choose to offer,
|
| 166 |
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
| 167 |
+
or other liability obligations and/or rights consistent with this
|
| 168 |
+
License. However, in accepting such obligations, You may act only
|
| 169 |
+
on Your own behalf and on Your sole responsibility, not on behalf
|
| 170 |
+
of any other Contributor, and only if You agree to indemnify,
|
| 171 |
+
defend, and hold each Contributor harmless for any liability
|
| 172 |
+
incurred by, or claims asserted against, such Contributor by reason
|
| 173 |
+
of your accepting any such warranty or additional liability.
|
| 174 |
+
|
| 175 |
+
END OF TERMS AND CONDITIONS
|
| 176 |
+
|
| 177 |
+
Copyright 2026 AEGIS-Reason Contributors
|
| 178 |
+
|
| 179 |
+
Licensed under the Apache License, Version 2.0 (the "License");
|
| 180 |
+
you may not use this file except in compliance with the License.
|
| 181 |
+
You may obtain a copy of the License at
|
| 182 |
+
|
| 183 |
+
http://www.apache.org/licenses/LICENSE-2.0
|
| 184 |
+
|
| 185 |
+
Unless required by applicable law or agreed to in writing, software
|
| 186 |
+
distributed under the License is distributed on an "AS IS" BASIS,
|
| 187 |
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 188 |
+
See the License for the specific language governing permissions and
|
| 189 |
+
limitations under the License.
|
aegis-reason/aegis-reason/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+

|
| 2 |
+
|
| 3 |
+
# AEGIS-Reason: Physical AI for Disaster Rescue
|
| 4 |
+
|
| 5 |
+
> **Cosmos Cookoff 2026** — Post-training Cosmos Reason 2 for multi-robot disaster rescue coordination
|
| 6 |
+
|
| 7 |
+
AEGIS teaches [Cosmos Reason 2](https://huggingface.co/nvidia/Cosmos-Reason2-2B) to analyze disaster scenes and produce structured physical reasoning chains that guide multi-robot rescue operations. We built the full pipeline: simulation → synthetic data → SFT → GRPO reinforcement learning → evaluation.
|
| 8 |
+
|
| 9 |
+
**The core insight:** A physics simulation can generate unlimited ground-truth reasoning chains, enabling both supervised fine-tuning *and* RL with a deterministic reward signal — no human annotation required.
|
| 10 |
+
|
| 11 |
+
## Quick Start (CPU only, ~30 seconds)
|
| 12 |
+
|
| 13 |
+
```bash
|
| 14 |
+
git clone https://github.com/<your-username>/aegis-reason.git
|
| 15 |
+
cd aegis-reason
|
| 16 |
+
pip install numpy Pillow matplotlib
|
| 17 |
+
python scripts/aegis_e2e_test.py
|
| 18 |
+
```
|
| 19 |
+
|
| 20 |
+
Expected output: `7/7 passed — ALL PASSED`
|
| 21 |
+
|
| 22 |
+
## What It Does
|
| 23 |
+
|
| 24 |
+
A 20×20 grid world with rising floodwaters, 3 rescue robots, and 7 trapped survivors. The model must:
|
| 25 |
+
|
| 26 |
+
1. **See** the disaster scene (top-down frame, 640×640)
|
| 27 |
+
2. **Ground** entities spatially (robots, survivors, flood zones, sectors)
|
| 28 |
+
3. **Predict** flood expansion dynamics over time
|
| 29 |
+
4. **Reason** about rescue urgency using threat proximity
|
| 30 |
+
5. **Decide** optimal robot-to-survivor assignments
|
| 31 |
+
|
| 32 |
+
| | |
|
| 33 |
+
|---|---|
|
| 34 |
+
|  |  |
|
| 35 |
+
| *Step 0 — Flood just starting* | *Step 4 — Flood expanding, 2 rescued* |
|
| 36 |
+
|
| 37 |
+
### Sample Reasoning Chain
|
| 38 |
+
|
| 39 |
+
```
|
| 40 |
+
[SPATIAL GROUNDING] Grid: 20×20. 5 survivors remaining. 18 flood cells.
|
| 41 |
+
Robot 0: position (12,11), sector 11. Robot 1: position (10,4), sector 9...
|
| 42 |
+
|
| 43 |
+
[TEMPORAL DYNAMICS] Current step: 4. Flood expanding slowly.
|
| 44 |
+
Predicted flood cells at step 7: ~22...
|
| 45 |
+
|
| 46 |
+
[CAUSAL REASONING] Survivor (1,15): urgency CRITICAL —
|
| 47 |
+
flood frontier is 2 cells away. Nearest robot: 0 at distance 15...
|
| 48 |
+
|
| 49 |
+
[DECISION] Recommended: Robot 0 → survivor (13,11), distance 1 step.
|
| 50 |
+
Robot 2 → survivor (18,9), distance 5 steps...
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
## Architecture
|
| 54 |
+
|
| 55 |
+
```
|
| 56 |
+
┌─────────────────────────────────────────────────────────────┐
|
| 57 |
+
│ MAELSTROM Simulation │
|
| 58 |
+
│ ┌────────────┐ ┌──────────┐ ┌───────────┐ ┌────────────┐ │
|
| 59 |
+
│ │ Hydro Flood│ │ Bayesian │ │ Fleet │ │ A* + RL │ │
|
| 60 |
+
│ │ Model │ │ Beliefs │ │ Coord │ │ Planning │ │
|
| 61 |
+
│ └────────────┘ └──────────┘ └───────────┘ └────────────┘ │
|
| 62 |
+
└──────────────────────┬──────────────────────────────────────┘
|
| 63 |
+
│ captures every N steps
|
| 64 |
+
┌────────────┼────────────┐
|
| 65 |
+
▼ ▼ ▼
|
| 66 |
+
┌──────────┐ ┌──────────┐ ┌──────────┐
|
| 67 |
+
│ Top-down │ │ Ego-view │ │ Reasoning│
|
| 68 |
+
│ 640×640 │ │ 640×640 │ │ Chain │
|
| 69 |
+
│ PNG │ │ PNG │ │ JSON │
|
| 70 |
+
└──────────┘ └──────────┘ └──────────┘
|
| 71 |
+
│ │ │
|
| 72 |
+
└────────────┼────────────┘
|
| 73 |
+
▼
|
| 74 |
+
┌────────────────┐ ┌────────────────┐
|
| 75 |
+
│ SFT Training │ ───▶ │ GRPO RL │
|
| 76 |
+
│ cosmos-rl │ │ VARP Reward │
|
| 77 |
+
│ 5 epochs │ │ 2 epochs │
|
| 78 |
+
└────────────────┘ └────────────────┘
|
| 79 |
+
│
|
| 80 |
+
▼
|
| 81 |
+
┌────────────────┐
|
| 82 |
+
│ AEGIS-Reason │
|
| 83 |
+
│ Cosmos Reason 2│
|
| 84 |
+
│ Fine-tuned │
|
| 85 |
+
└────────────────┘
|
| 86 |
+
```
|
| 87 |
+
|
| 88 |
+
## Dataset
|
| 89 |
+
|
| 90 |
+
**12,578 training pairs** across 320 scenarios (40 seeds × 4 budgets × 2 intel modes).
|
| 91 |
+
|
| 92 |
+
| Component | Count | Size |
|
| 93 |
+
|-----------|-------|------|
|
| 94 |
+
| Top-down frames | 6,289 | 95 MB |
|
| 95 |
+
| Egocentric frames | 6,289 | 49 MB |
|
| 96 |
+
| Reasoning chains | 6,289 | 22 MB |
|
| 97 |
+
|
| 98 |
+
Generate the full dataset in ~4 minutes on any CPU:
|
| 99 |
+
|
| 100 |
+
```bash
|
| 101 |
+
python aegis_data_generator.py --seeds 40 --output aegis_dataset
|
| 102 |
+
python aegis_convert_llava.py --input aegis_dataset/sft_data.jsonl --output aegis_llava
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
## Training Pipeline
|
| 106 |
+
|
| 107 |
+
### Phase 1: SFT (~45 min on 8× H100)
|
| 108 |
+
|
| 109 |
+
```bash
|
| 110 |
+
# On Nebius
|
| 111 |
+
cd cosmos-reason2/examples/cosmos_rl
|
| 112 |
+
cosmos-rl --config /path/to/configs/aegis_sft.toml /path/to/aegis_dataloader.py
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
### Phase 2: GRPO RL (~2-3 hours on 8× H100)
|
| 116 |
+
|
| 117 |
+
```bash
|
| 118 |
+
cosmos-rl --config /path/to/configs/aegis_grpo.toml /path/to/aegis_grpo_reward.py
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
### VARP Evaluation
|
| 122 |
+
|
| 123 |
+
The VARP (Visual-Action Reasoning Precision) framework scores predictions across 4 axes:
|
| 124 |
+
|
| 125 |
+
| Axis | Weight | Measures |
|
| 126 |
+
|------|--------|----------|
|
| 127 |
+
| Spatial | 30% | Entity identification + positions |
|
| 128 |
+
| Temporal | 20% | Flood count + expansion prediction |
|
| 129 |
+
| Causal | 25% | Urgency classification accuracy |
|
| 130 |
+
| Decision | 25% | Robot-survivor assignment quality |
|
| 131 |
+
|
| 132 |
+
Validated: 97.4% for perfect predictions, ~5% for vague responses → **1.42 reward spread** for GRPO.
|
| 133 |
+
|
| 134 |
+
## Repository Structure
|
| 135 |
+
|
| 136 |
+
```
|
| 137 |
+
aegis-reason/
|
| 138 |
+
├── README.md
|
| 139 |
+
├── Dockerfile # Full reproducibility container
|
| 140 |
+
├── requirements.txt # CPU: numpy, Pillow, matplotlib
|
| 141 |
+
│
|
| 142 |
+
├── maelstrom_core.py # Physics simulation engine
|
| 143 |
+
├── aegis_render_engine.py # Dual-view renderer + chain oracle
|
| 144 |
+
├── aegis_data_generator.py # Batch dataset generation
|
| 145 |
+
├── aegis_convert_llava.py # → LLaVA format for cosmos-rl
|
| 146 |
+
├── aegis_dataloader.py # cosmos-rl dataset class
|
| 147 |
+
├── aegis_grpo_reward.py # VARP reward function for GRPO
|
| 148 |
+
├── aegis_inference.py # Inference engine
|
| 149 |
+
├── aegis_varp.py # 4-axis evaluation framework
|
| 150 |
+
│
|
| 151 |
+
├── configs/
|
| 152 |
+
│ ├── aegis_sft.toml # SFT training config
|
| 153 |
+
│ └── aegis_grpo.toml # GRPO RL config
|
| 154 |
+
│
|
| 155 |
+
├── scripts/
|
| 156 |
+
│ ├── aegis_e2e_test.py # Validation suite (7 tests)
|
| 157 |
+
│ ├── nebius_train.sh # One-command Nebius deployment
|
| 158 |
+
│ └── push_to_hub.py # HuggingFace dataset upload
|
| 159 |
+
│
|
| 160 |
+
├── demo/
|
| 161 |
+
│ ├── aegis_dashboard.jsx # Interactive React dashboard
|
| 162 |
+
│ └── aegis_scenario_demo.gif # Animated rescue scenario
|
| 163 |
+
│
|
| 164 |
+
├── samples/ # Visual samples for browsing
|
| 165 |
+
│ ├── topdown_step0.png
|
| 166 |
+
│ ├── topdown_step4.png
|
| 167 |
+
│ ├── egocentric_sample.png
|
| 168 |
+
│ └── sample_chain.json
|
| 169 |
+
│
|
| 170 |
+
└── docs/
|
| 171 |
+
├── cookbook_recipe.md # Cosmos Cookbook-style recipe
|
| 172 |
+
├── hf_dataset_card.md # HuggingFace dataset README
|
| 173 |
+
└── benchmark_analysis.json # Dataset complexity analysis
|
| 174 |
+
```
|
| 175 |
+
|
| 176 |
+
## Real-World Applications
|
| 177 |
+
|
| 178 |
+
- **Urban search & rescue** after earthquakes, hurricanes, floods
|
| 179 |
+
- **Wildfire evacuation** — coordinating multiple response teams
|
| 180 |
+
- **Warehouse robotics** — multi-agent coordination under hazards
|
| 181 |
+
- **Autonomous vehicle** fleet routing around road closures
|
| 182 |
+
|
| 183 |
+
## Built With
|
| 184 |
+
|
| 185 |
+
- [NVIDIA Cosmos Reason 2](https://huggingface.co/nvidia/Cosmos-Reason2-2B) — Base VLM
|
| 186 |
+
- [cosmos-rl](https://github.com/nvidia-cosmos/cosmos-rl) — SFT + GRPO training
|
| 187 |
+
- [Cosmos Cookbook](https://nvidia-cosmos.github.io/cosmos-cookbook/) — Recipes and patterns
|
| 188 |
+
- [Nebius](https://nebius.com) — GPU compute (8× H100)
|
| 189 |
+
|
| 190 |
+
## License
|
| 191 |
+
|
| 192 |
+
Code: [Apache 2.0](LICENSE) · Model weights: [NVIDIA Open Model License](https://developer.nvidia.com/open-model-license) · Dataset: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
|
aegis-reason/aegis-reason/aegis_convert_llava.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS Data Converter — Transform AEGIS SFT dataset to LLaVA format for cosmos-rl
|
| 3 |
+
==================================================================================
|
| 4 |
+
cosmos-rl expects the LLaVA dataset format:
|
| 5 |
+
- JSON array of entries
|
| 6 |
+
- Each entry has: id, image (relative path), conversations
|
| 7 |
+
- Conversations use "from": "human"/"gpt" (NOT "role": "user"/"assistant")
|
| 8 |
+
- Image placeholder is <image> in the human turn
|
| 9 |
+
|
| 10 |
+
This script:
|
| 11 |
+
1. Reads our aegis_dataset/sft_data.jsonl
|
| 12 |
+
2. Converts to LLaVA format
|
| 13 |
+
3. Splits into train/val (95/5)
|
| 14 |
+
4. Outputs annotations.json for cosmos-rl consumption
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
import random
|
| 20 |
+
import argparse
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from typing import Dict, List
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def convert_conversation(conv: List[Dict]) -> List[Dict]:
|
| 26 |
+
"""Convert from role-based format to LLaVA from-based format."""
|
| 27 |
+
llava_conv = []
|
| 28 |
+
for turn in conv:
|
| 29 |
+
role = turn.get("role", "")
|
| 30 |
+
content = turn.get("content", "")
|
| 31 |
+
|
| 32 |
+
if role == "system":
|
| 33 |
+
# cosmos-rl doesn't use system turns in LLaVA format;
|
| 34 |
+
# prepend system prompt to the first human turn
|
| 35 |
+
continue
|
| 36 |
+
elif role == "user":
|
| 37 |
+
llava_conv.append({"from": "human", "value": content})
|
| 38 |
+
elif role == "assistant":
|
| 39 |
+
llava_conv.append({"from": "gpt", "value": content})
|
| 40 |
+
|
| 41 |
+
return llava_conv
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def inject_system_prompt(conversations: List[Dict], system_content: str) -> List[Dict]:
|
| 45 |
+
"""Inject system prompt into the first human turn for context."""
|
| 46 |
+
if conversations and conversations[0]["from"] == "human":
|
| 47 |
+
conversations[0]["value"] = (
|
| 48 |
+
f"{system_content}\n\n{conversations[0]['value']}"
|
| 49 |
+
)
|
| 50 |
+
return conversations
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def convert_aegis_to_llava(
|
| 54 |
+
input_jsonl: str,
|
| 55 |
+
output_dir: str,
|
| 56 |
+
media_root: str = "",
|
| 57 |
+
val_ratio: float = 0.05,
|
| 58 |
+
seed: int = 42,
|
| 59 |
+
include_system: bool = True,
|
| 60 |
+
views: str = "both", # "topdown", "egocentric", or "both"
|
| 61 |
+
max_samples: int = 0, # 0 = all
|
| 62 |
+
) -> Dict:
|
| 63 |
+
"""Convert AEGIS SFT data to LLaVA format.
|
| 64 |
+
|
| 65 |
+
Args:
|
| 66 |
+
input_jsonl: Path to aegis sft_data.jsonl
|
| 67 |
+
output_dir: Where to write LLaVA annotations
|
| 68 |
+
media_root: Base path prefix for image files (if absolute, set to "")
|
| 69 |
+
val_ratio: Fraction for validation split
|
| 70 |
+
seed: Random seed for reproducible splitting
|
| 71 |
+
include_system: Whether to inject system prompt into human turn
|
| 72 |
+
views: Which views to include ("topdown", "egocentric", or "both")
|
| 73 |
+
max_samples: Cap on total samples (0 = unlimited)
|
| 74 |
+
|
| 75 |
+
Returns:
|
| 76 |
+
Dict with conversion statistics
|
| 77 |
+
"""
|
| 78 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 79 |
+
|
| 80 |
+
# Read source data
|
| 81 |
+
records = []
|
| 82 |
+
with open(input_jsonl, "r") as f:
|
| 83 |
+
for line in f:
|
| 84 |
+
record = json.loads(line.strip())
|
| 85 |
+
# Filter by view
|
| 86 |
+
if views != "both" and record.get("view") != views:
|
| 87 |
+
continue
|
| 88 |
+
records.append(record)
|
| 89 |
+
|
| 90 |
+
if max_samples > 0:
|
| 91 |
+
random.seed(seed)
|
| 92 |
+
random.shuffle(records)
|
| 93 |
+
records = records[:max_samples]
|
| 94 |
+
|
| 95 |
+
# Convert
|
| 96 |
+
llava_entries = []
|
| 97 |
+
stats = {"total": 0, "topdown": 0, "egocentric": 0, "skipped": 0}
|
| 98 |
+
|
| 99 |
+
for record in records:
|
| 100 |
+
sample_id = record["id"]
|
| 101 |
+
image_path = record["image"]
|
| 102 |
+
conversations = record.get("conversations", [])
|
| 103 |
+
|
| 104 |
+
if not conversations or not image_path:
|
| 105 |
+
stats["skipped"] += 1
|
| 106 |
+
continue
|
| 107 |
+
|
| 108 |
+
# Build image path relative to media_root
|
| 109 |
+
if media_root:
|
| 110 |
+
# Make image path relative to media_root
|
| 111 |
+
if image_path.startswith(media_root):
|
| 112 |
+
rel_path = image_path[len(media_root):].lstrip("/")
|
| 113 |
+
else:
|
| 114 |
+
rel_path = image_path
|
| 115 |
+
else:
|
| 116 |
+
rel_path = image_path
|
| 117 |
+
|
| 118 |
+
# Convert conversations
|
| 119 |
+
system_content = ""
|
| 120 |
+
llava_conv = []
|
| 121 |
+
for turn in conversations:
|
| 122 |
+
if turn["role"] == "system":
|
| 123 |
+
system_content = turn["content"]
|
| 124 |
+
elif turn["role"] == "user":
|
| 125 |
+
llava_conv.append({"from": "human", "value": turn["content"]})
|
| 126 |
+
elif turn["role"] == "assistant":
|
| 127 |
+
llava_conv.append({"from": "gpt", "value": turn["content"]})
|
| 128 |
+
|
| 129 |
+
# Optionally inject system prompt
|
| 130 |
+
if include_system and system_content and llava_conv:
|
| 131 |
+
llava_conv[0]["value"] = f"{system_content}\n\n{llava_conv[0]['value']}"
|
| 132 |
+
|
| 133 |
+
entry = {
|
| 134 |
+
"id": sample_id,
|
| 135 |
+
"image": rel_path,
|
| 136 |
+
"conversations": llava_conv,
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
llava_entries.append(entry)
|
| 140 |
+
stats["total"] += 1
|
| 141 |
+
if record.get("view") == "topdown":
|
| 142 |
+
stats["topdown"] += 1
|
| 143 |
+
else:
|
| 144 |
+
stats["egocentric"] += 1
|
| 145 |
+
|
| 146 |
+
# Split train/val
|
| 147 |
+
random.seed(seed)
|
| 148 |
+
random.shuffle(llava_entries)
|
| 149 |
+
n_val = max(1, int(len(llava_entries) * val_ratio))
|
| 150 |
+
val_entries = llava_entries[:n_val]
|
| 151 |
+
train_entries = llava_entries[n_val:]
|
| 152 |
+
|
| 153 |
+
# Write output files
|
| 154 |
+
train_path = os.path.join(output_dir, "annotations_train.json")
|
| 155 |
+
val_path = os.path.join(output_dir, "annotations_val.json")
|
| 156 |
+
full_path = os.path.join(output_dir, "annotations.json")
|
| 157 |
+
|
| 158 |
+
with open(train_path, "w") as f:
|
| 159 |
+
json.dump(train_entries, f, indent=2)
|
| 160 |
+
with open(val_path, "w") as f:
|
| 161 |
+
json.dump(val_entries, f, indent=2)
|
| 162 |
+
with open(full_path, "w") as f:
|
| 163 |
+
json.dump(llava_entries, f, indent=2)
|
| 164 |
+
|
| 165 |
+
stats["train"] = len(train_entries)
|
| 166 |
+
stats["val"] = len(val_entries)
|
| 167 |
+
stats["train_path"] = train_path
|
| 168 |
+
stats["val_path"] = val_path
|
| 169 |
+
stats["full_path"] = full_path
|
| 170 |
+
|
| 171 |
+
# Write stats
|
| 172 |
+
stats_path = os.path.join(output_dir, "conversion_stats.json")
|
| 173 |
+
with open(stats_path, "w") as f:
|
| 174 |
+
json.dump(stats, f, indent=2)
|
| 175 |
+
|
| 176 |
+
return stats
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def main():
|
| 180 |
+
parser = argparse.ArgumentParser(description="Convert AEGIS SFT data to LLaVA format")
|
| 181 |
+
parser.add_argument("--input", default="aegis_dataset/sft_data.jsonl",
|
| 182 |
+
help="Path to AEGIS SFT JSONL file")
|
| 183 |
+
parser.add_argument("--output", default="aegis_llava",
|
| 184 |
+
help="Output directory for LLaVA annotations")
|
| 185 |
+
parser.add_argument("--media-root", default="",
|
| 186 |
+
help="Base path prefix for media files")
|
| 187 |
+
parser.add_argument("--val-ratio", type=float, default=0.05,
|
| 188 |
+
help="Validation split ratio")
|
| 189 |
+
parser.add_argument("--views", choices=["topdown", "egocentric", "both"],
|
| 190 |
+
default="both", help="Which views to include")
|
| 191 |
+
parser.add_argument("--max-samples", type=int, default=0,
|
| 192 |
+
help="Max samples (0=all)")
|
| 193 |
+
parser.add_argument("--no-system", action="store_true",
|
| 194 |
+
help="Don't inject system prompt into human turn")
|
| 195 |
+
args = parser.parse_args()
|
| 196 |
+
|
| 197 |
+
print(f"AEGIS → LLaVA Converter")
|
| 198 |
+
print(f" Input: {args.input}")
|
| 199 |
+
print(f" Output: {args.output}")
|
| 200 |
+
print(f" Views: {args.views}")
|
| 201 |
+
print(f" Val ratio: {args.val_ratio}")
|
| 202 |
+
print()
|
| 203 |
+
|
| 204 |
+
stats = convert_aegis_to_llava(
|
| 205 |
+
input_jsonl=args.input,
|
| 206 |
+
output_dir=args.output,
|
| 207 |
+
media_root=args.media_root,
|
| 208 |
+
val_ratio=args.val_ratio,
|
| 209 |
+
include_system=not args.no_system,
|
| 210 |
+
views=args.views,
|
| 211 |
+
max_samples=args.max_samples,
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
print(f"Conversion complete:")
|
| 215 |
+
print(f" Total: {stats['total']} (topdown={stats['topdown']}, ego={stats['egocentric']})")
|
| 216 |
+
print(f" Train: {stats['train']}")
|
| 217 |
+
print(f" Val: {stats['val']}")
|
| 218 |
+
print(f" Skipped: {stats['skipped']}")
|
| 219 |
+
print(f" Train file: {stats['train_path']}")
|
| 220 |
+
print(f" Val file: {stats['val_path']}")
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
if __name__ == "__main__":
|
| 224 |
+
main()
|
aegis-reason/aegis-reason/aegis_data_generator.py
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS Batch Data Generator — Mass-produce SFT training pairs
|
| 3 |
+
=============================================================
|
| 4 |
+
Runs MAELSTROM simulations across varied seeds, budgets, and
|
| 5 |
+
intel conditions, capturing (frame, reasoning_chain) pairs at
|
| 6 |
+
every timestep via the AEGIS render engine.
|
| 7 |
+
|
| 8 |
+
Output structure:
|
| 9 |
+
aegis_dataset/
|
| 10 |
+
├── topdown/ # 640×640 global frames
|
| 11 |
+
├── egocentric/ # 640×640 per-robot FOV frames
|
| 12 |
+
├── chains/ # JSON reasoning chains (4 components)
|
| 13 |
+
├── pairs/ # Combined (frame, chain) pair records
|
| 14 |
+
├── manifest.json # Full dataset manifest with metadata
|
| 15 |
+
└── sft_data.jsonl # Ready-to-use SFT training format
|
| 16 |
+
|
| 17 |
+
Design parameters:
|
| 18 |
+
- 40 seeds × 4 budgets × {no_intel, with_intel} = 320 scenarios
|
| 19 |
+
- ~20-100 steps per scenario → ~2,000-6,000+ pairs
|
| 20 |
+
- Capture every 3rd step (reduces redundancy, keeps dynamics)
|
| 21 |
+
- Deterministic: same config always produces same dataset
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
import os
|
| 25 |
+
import sys
|
| 26 |
+
import json
|
| 27 |
+
import time
|
| 28 |
+
import numpy as np
|
| 29 |
+
from typing import Dict, List, Tuple, Optional
|
| 30 |
+
|
| 31 |
+
# Import from our modules
|
| 32 |
+
from maelstrom_core import (
|
| 33 |
+
SimConfig, SECTOR_GRID, get_sector_for_cell, get_scan_radius,
|
| 34 |
+
HydroDynamicWorld, SensorFusion, BayesianBeliefState,
|
| 35 |
+
FleetCoordinator, HierarchicalPlanner, ProtoMotions,
|
| 36 |
+
AdaptiveRLTrainer, RescueCommander, compute_fleet_known_grid,
|
| 37 |
+
run_simulation,
|
| 38 |
+
)
|
| 39 |
+
from aegis_render_engine import (
|
| 40 |
+
TopDownRenderer, EgocentricRenderer, ReasoningChainGenerator,
|
| 41 |
+
GRID_SIZE,
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# ============================================================
|
| 46 |
+
# DATASET CONFIGURATION
|
| 47 |
+
# ============================================================
|
| 48 |
+
class DatasetConfig:
|
| 49 |
+
"""Controls data generation volume and diversity."""
|
| 50 |
+
|
| 51 |
+
# Scenario parameters
|
| 52 |
+
SEEDS = list(range(1, 41)) # 40 diverse seeds
|
| 53 |
+
BUDGETS = [0.3, 1.0, 2.0, 3.0] # 4 budget tiers (reactive -> strategic)
|
| 54 |
+
|
| 55 |
+
# Intel conditions per scenario
|
| 56 |
+
INTEL_MODE = True # Generate both with/without intel
|
| 57 |
+
|
| 58 |
+
# Capture strategy
|
| 59 |
+
CAPTURE_INTERVAL = 3 # Capture every Nth step
|
| 60 |
+
CAPTURE_FIRST_STEPS = 5 # Always capture first N steps (early dynamics)
|
| 61 |
+
MAX_STEPS = 80 # Shorter than default 100 (saves time)
|
| 62 |
+
|
| 63 |
+
# Frame rendering
|
| 64 |
+
RENDER_TOPDOWN = True
|
| 65 |
+
RENDER_EGOCENTRIC = True
|
| 66 |
+
RENDER_EGO_ROBOTS = [0] # Robot 0 only for speed; expand later
|
| 67 |
+
|
| 68 |
+
# Output
|
| 69 |
+
OUTPUT_DIR = "aegis_dataset"
|
| 70 |
+
|
| 71 |
+
# SFT format
|
| 72 |
+
SFT_SYSTEM_PROMPT = (
|
| 73 |
+
"You are AEGIS-Reason, a physical AI reasoning model for disaster rescue coordination. "
|
| 74 |
+
"Given a visual frame from a 20x20 grid disaster simulation, provide detailed "
|
| 75 |
+
"chain-of-thought reasoning about: (1) spatial grounding - identify and locate all "
|
| 76 |
+
"entities (robots, survivors, flood zones), (2) temporal dynamics - predict flood "
|
| 77 |
+
"expansion, (3) causal reasoning - determine rescue urgency based on threat proximity "
|
| 78 |
+
"and robot distances, (4) decision - recommend optimal robot-to-survivor assignments."
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
# ============================================================
|
| 83 |
+
# SMART INTEL SELECTOR
|
| 84 |
+
# ============================================================
|
| 85 |
+
def find_survivor_sectors(grid: np.ndarray) -> List[int]:
|
| 86 |
+
"""Find which sectors contain survivors in the ground truth grid."""
|
| 87 |
+
sectors_with_survivors = set()
|
| 88 |
+
for r in range(GRID_SIZE):
|
| 89 |
+
for c in range(GRID_SIZE):
|
| 90 |
+
if grid[r, c] == 2:
|
| 91 |
+
sectors_with_survivors.add(get_sector_for_cell(r, c))
|
| 92 |
+
return sorted(sectors_with_survivors)
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def pick_intel_sectors(survivor_sectors: List[int], seed: int) -> List[int]:
|
| 96 |
+
"""Pick 1-2 sectors to use as intel. Deterministic per seed."""
|
| 97 |
+
if not survivor_sectors:
|
| 98 |
+
return []
|
| 99 |
+
rng = np.random.RandomState(seed + 7777)
|
| 100 |
+
n_sectors = rng.choice([1, 2], p=[0.6, 0.4])
|
| 101 |
+
n_sectors = min(n_sectors, len(survivor_sectors))
|
| 102 |
+
chosen = rng.choice(survivor_sectors, size=n_sectors, replace=False)
|
| 103 |
+
return sorted(chosen.tolist())
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
# ============================================================
|
| 107 |
+
# BATCH GENERATOR
|
| 108 |
+
# ============================================================
|
| 109 |
+
class AEGISBatchGenerator:
|
| 110 |
+
"""Orchestrates mass data generation across all scenario conditions."""
|
| 111 |
+
|
| 112 |
+
def __init__(self, config: DatasetConfig = None):
|
| 113 |
+
self.config = config or DatasetConfig()
|
| 114 |
+
self.output_dir = self.config.OUTPUT_DIR
|
| 115 |
+
|
| 116 |
+
# Renderers
|
| 117 |
+
self.topdown_renderer = TopDownRenderer()
|
| 118 |
+
self.ego_renderer = EgocentricRenderer()
|
| 119 |
+
self.chain_gen = ReasoningChainGenerator()
|
| 120 |
+
|
| 121 |
+
# Tracking
|
| 122 |
+
self.total_pairs = 0
|
| 123 |
+
self.scenario_results = []
|
| 124 |
+
self.sft_records = []
|
| 125 |
+
|
| 126 |
+
# Create output directories
|
| 127 |
+
for subdir in ["topdown", "egocentric", "chains", "pairs"]:
|
| 128 |
+
os.makedirs(f"{self.output_dir}/{subdir}", exist_ok=True)
|
| 129 |
+
|
| 130 |
+
def generate_all(self) -> Dict:
|
| 131 |
+
"""Run all scenarios and generate the full dataset."""
|
| 132 |
+
start_time = time.time()
|
| 133 |
+
total_scenarios = len(self.config.SEEDS) * len(self.config.BUDGETS)
|
| 134 |
+
if self.config.INTEL_MODE:
|
| 135 |
+
total_scenarios *= 2
|
| 136 |
+
|
| 137 |
+
print(f"AEGIS Data Generator")
|
| 138 |
+
print(f" Seeds: {len(self.config.SEEDS)}, Budgets: {self.config.BUDGETS}")
|
| 139 |
+
print(f" Intel modes: {'with + without' if self.config.INTEL_MODE else 'without only'}")
|
| 140 |
+
print(f" Total scenarios: {total_scenarios}")
|
| 141 |
+
print(f" Capture interval: every {self.config.CAPTURE_INTERVAL} steps + first {self.config.CAPTURE_FIRST_STEPS}")
|
| 142 |
+
print(f" Ego robots: {self.config.RENDER_EGO_ROBOTS}")
|
| 143 |
+
print(f" Output: {self.output_dir}/")
|
| 144 |
+
print(f"{'='*60}")
|
| 145 |
+
|
| 146 |
+
scenario_idx = 0
|
| 147 |
+
for seed in self.config.SEEDS:
|
| 148 |
+
for budget in self.config.BUDGETS:
|
| 149 |
+
# --- Run WITHOUT intel ---
|
| 150 |
+
scenario_idx += 1
|
| 151 |
+
self._run_scenario(
|
| 152 |
+
seed=seed, budget=budget, priority_sectors=[],
|
| 153 |
+
scenario_idx=scenario_idx, total=total_scenarios, label="no_intel",
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
# --- Run WITH intel ---
|
| 157 |
+
if self.config.INTEL_MODE:
|
| 158 |
+
scenario_idx += 1
|
| 159 |
+
intel_sectors = self._peek_survivor_sectors(seed)
|
| 160 |
+
self._run_scenario(
|
| 161 |
+
seed=seed, budget=budget, priority_sectors=intel_sectors,
|
| 162 |
+
scenario_idx=scenario_idx, total=total_scenarios, label="with_intel",
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# Write SFT training file
|
| 166 |
+
sft_path = f"{self.output_dir}/sft_data.jsonl"
|
| 167 |
+
|
| 168 |
+
class NpEncoder(json.JSONEncoder):
|
| 169 |
+
def default(self, obj):
|
| 170 |
+
if isinstance(obj, np.integer): return int(obj)
|
| 171 |
+
if isinstance(obj, np.floating): return float(obj)
|
| 172 |
+
if isinstance(obj, np.ndarray): return obj.tolist()
|
| 173 |
+
return super().default(obj)
|
| 174 |
+
|
| 175 |
+
with open(sft_path, "w") as f:
|
| 176 |
+
for record in self.sft_records:
|
| 177 |
+
f.write(json.dumps(record, cls=NpEncoder) + "\n")
|
| 178 |
+
|
| 179 |
+
# Write manifest
|
| 180 |
+
elapsed = time.time() - start_time
|
| 181 |
+
manifest = {
|
| 182 |
+
"dataset": "AEGIS-Reason SFT Training Data",
|
| 183 |
+
"version": "1.0",
|
| 184 |
+
"generated_at": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 185 |
+
"generation_time_seconds": round(elapsed, 1),
|
| 186 |
+
"total_pairs": self.total_pairs,
|
| 187 |
+
"total_sft_records": len(self.sft_records),
|
| 188 |
+
"total_scenarios": len(self.scenario_results),
|
| 189 |
+
"config": {
|
| 190 |
+
"seeds": self.config.SEEDS,
|
| 191 |
+
"budgets": self.config.BUDGETS,
|
| 192 |
+
"intel_mode": self.config.INTEL_MODE,
|
| 193 |
+
"capture_interval": self.config.CAPTURE_INTERVAL,
|
| 194 |
+
"max_steps": self.config.MAX_STEPS,
|
| 195 |
+
"ego_robots": self.config.RENDER_EGO_ROBOTS,
|
| 196 |
+
"grid_size": GRID_SIZE,
|
| 197 |
+
"num_agents": SimConfig.NUM_AGENTS,
|
| 198 |
+
"num_survivors": SimConfig.NUM_SURVIVORS,
|
| 199 |
+
},
|
| 200 |
+
"outcome_summary": self._compute_outcome_summary(),
|
| 201 |
+
"sft_file": sft_path,
|
| 202 |
+
}
|
| 203 |
+
manifest_path = f"{self.output_dir}/manifest.json"
|
| 204 |
+
with open(manifest_path, "w") as f:
|
| 205 |
+
json.dump(manifest, f, indent=2, cls=NpEncoder)
|
| 206 |
+
|
| 207 |
+
print(f"\n{'='*60}")
|
| 208 |
+
print(f"AEGIS Dataset Generation Complete!")
|
| 209 |
+
print(f" Total pairs captured: {self.total_pairs}")
|
| 210 |
+
print(f" SFT records: {len(self.sft_records)}")
|
| 211 |
+
print(f" Scenarios: {len(self.scenario_results)}")
|
| 212 |
+
print(f" Time: {elapsed:.1f}s ({elapsed/60:.1f}min)")
|
| 213 |
+
print(f" Manifest: {manifest_path}")
|
| 214 |
+
print(f" SFT file: {sft_path}")
|
| 215 |
+
|
| 216 |
+
return manifest
|
| 217 |
+
|
| 218 |
+
def _compute_outcome_summary(self) -> Dict:
|
| 219 |
+
"""Compute summary statistics across all scenarios."""
|
| 220 |
+
if not self.scenario_results:
|
| 221 |
+
return {}
|
| 222 |
+
successes = sum(1 for s in self.scenario_results if s['outcome'] == 'SUCCESS')
|
| 223 |
+
timeouts = sum(1 for s in self.scenario_results if s['outcome'] == 'TIMEOUT')
|
| 224 |
+
steps = [s['steps'] for s in self.scenario_results]
|
| 225 |
+
rescued = [s['rescued'] for s in self.scenario_results]
|
| 226 |
+
return {
|
| 227 |
+
"total_scenarios": len(self.scenario_results),
|
| 228 |
+
"successes": successes,
|
| 229 |
+
"timeouts": timeouts,
|
| 230 |
+
"success_rate": round(successes / len(self.scenario_results), 3),
|
| 231 |
+
"avg_steps": round(np.mean(steps), 1),
|
| 232 |
+
"avg_rescued": round(np.mean(rescued), 2),
|
| 233 |
+
"min_steps": min(steps),
|
| 234 |
+
"max_steps": max(steps),
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
def _peek_survivor_sectors(self, seed: int) -> List[int]:
|
| 238 |
+
"""Quick peek at grid to find survivor sectors for intel selection."""
|
| 239 |
+
import random as _random
|
| 240 |
+
np.random.seed(seed)
|
| 241 |
+
_random.seed(seed)
|
| 242 |
+
env = HydroDynamicWorld()
|
| 243 |
+
state = env.reset()
|
| 244 |
+
survivor_sectors = find_survivor_sectors(state['grid'])
|
| 245 |
+
return pick_intel_sectors(survivor_sectors, seed)
|
| 246 |
+
|
| 247 |
+
def _run_scenario(self, seed, budget, priority_sectors, scenario_idx, total, label):
|
| 248 |
+
"""Run one scenario and capture data at selected timesteps."""
|
| 249 |
+
scenario_id = f"seed{seed:03d}_b{budget:.1f}_{label}"
|
| 250 |
+
captured_steps = []
|
| 251 |
+
pairs_this_scenario = [0] # mutable in closure
|
| 252 |
+
|
| 253 |
+
def capture_callback(state, commanders, coordinator, assignments, step, scan_radius, budget):
|
| 254 |
+
should_capture = False
|
| 255 |
+
if step < self.config.CAPTURE_FIRST_STEPS:
|
| 256 |
+
should_capture = True
|
| 257 |
+
elif step % self.config.CAPTURE_INTERVAL == 0:
|
| 258 |
+
should_capture = True
|
| 259 |
+
|
| 260 |
+
if not should_capture:
|
| 261 |
+
return
|
| 262 |
+
|
| 263 |
+
pair = self._capture_step(
|
| 264 |
+
state=state, commanders=commanders, assignments=assignments,
|
| 265 |
+
step=step, scan_radius=scan_radius, scenario_id=scenario_id,
|
| 266 |
+
priority_sectors=priority_sectors,
|
| 267 |
+
)
|
| 268 |
+
if pair:
|
| 269 |
+
captured_steps.append(step)
|
| 270 |
+
pairs_this_scenario[0] += 1
|
| 271 |
+
|
| 272 |
+
result = run_simulation(
|
| 273 |
+
seed=seed, budget=budget, priority_sectors=priority_sectors,
|
| 274 |
+
max_steps=self.config.MAX_STEPS, capture_callback=capture_callback,
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
self.total_pairs += pairs_this_scenario[0]
|
| 278 |
+
|
| 279 |
+
scenario_summary = {
|
| 280 |
+
"scenario_id": scenario_id,
|
| 281 |
+
"seed": seed, "budget": budget,
|
| 282 |
+
"priority_sectors": priority_sectors,
|
| 283 |
+
"intel_label": label,
|
| 284 |
+
"outcome": result['outcome'],
|
| 285 |
+
"steps": result['steps'],
|
| 286 |
+
"rescued": result['rescued'],
|
| 287 |
+
"explored_pct": result['explored_pct'],
|
| 288 |
+
"pairs_captured": pairs_this_scenario[0],
|
| 289 |
+
}
|
| 290 |
+
self.scenario_results.append(scenario_summary)
|
| 291 |
+
|
| 292 |
+
status = "+" if result['outcome'] == "SUCCESS" else "-"
|
| 293 |
+
print(f" [{scenario_idx:3d}/{total}] {status} {scenario_id}: "
|
| 294 |
+
f"{result['steps']:3d} steps, rescued={result['rescued']}, "
|
| 295 |
+
f"pairs={pairs_this_scenario[0]}")
|
| 296 |
+
|
| 297 |
+
def _capture_step(self, state, commanders, assignments, step, scan_radius,
|
| 298 |
+
scenario_id, priority_sectors):
|
| 299 |
+
"""Capture one timestep: render frame(s) + generate reasoning chain."""
|
| 300 |
+
grid = state['grid']
|
| 301 |
+
agents = state['agents']
|
| 302 |
+
rescued = state['rescued']
|
| 303 |
+
sample_id = f"{scenario_id}_step{step:03d}"
|
| 304 |
+
|
| 305 |
+
# --- Reasoning chain ---
|
| 306 |
+
chain = self.chain_gen.generate(
|
| 307 |
+
grid=grid, agent_positions=agents, step=step,
|
| 308 |
+
rescued=rescued, assignments=assignments, scan_radius=scan_radius,
|
| 309 |
+
)
|
| 310 |
+
chain_path = f"{self.output_dir}/chains/{sample_id}.json"
|
| 311 |
+
with open(chain_path, "w") as f:
|
| 312 |
+
json.dump(chain, f, indent=2, default=lambda x: int(x) if isinstance(x, np.integer) else float(x) if isinstance(x, np.floating) else x)
|
| 313 |
+
|
| 314 |
+
# --- Top-down frame ---
|
| 315 |
+
topdown_path = None
|
| 316 |
+
if self.config.RENDER_TOPDOWN:
|
| 317 |
+
flood_frontier = np.zeros((GRID_SIZE, GRID_SIZE), dtype=bool)
|
| 318 |
+
for r in range(GRID_SIZE):
|
| 319 |
+
for c in range(GRID_SIZE):
|
| 320 |
+
if grid[r, c] == 1:
|
| 321 |
+
for nr, nc in [(r-1,c), (r+1,c), (r,c-1), (r,c+1)]:
|
| 322 |
+
if 0 <= nr < GRID_SIZE and 0 <= nc < GRID_SIZE:
|
| 323 |
+
if grid[nr, nc] != 1:
|
| 324 |
+
flood_frontier[r, c] = True
|
| 325 |
+
break
|
| 326 |
+
|
| 327 |
+
topdown_img = self.topdown_renderer.render(
|
| 328 |
+
grid=grid, agent_positions=agents, step=step, rescued=rescued,
|
| 329 |
+
priority_sectors=priority_sectors, assignments=assignments,
|
| 330 |
+
scan_radius=scan_radius, flood_frontier=flood_frontier,
|
| 331 |
+
)
|
| 332 |
+
topdown_path = f"{self.output_dir}/topdown/{sample_id}.png"
|
| 333 |
+
topdown_img.save(topdown_path)
|
| 334 |
+
|
| 335 |
+
# --- Egocentric frame(s) ---
|
| 336 |
+
ego_paths = {}
|
| 337 |
+
if self.config.RENDER_EGOCENTRIC:
|
| 338 |
+
for robot_id in self.config.RENDER_EGO_ROBOTS:
|
| 339 |
+
if robot_id in agents:
|
| 340 |
+
belief = commanders[robot_id].belief_state.belief_grid if robot_id in commanders else None
|
| 341 |
+
ego_img = self.ego_renderer.render(
|
| 342 |
+
grid=grid, agent_id=robot_id, agent_positions=agents,
|
| 343 |
+
belief_grid=belief, scan_radius=scan_radius,
|
| 344 |
+
)
|
| 345 |
+
ego_path = f"{self.output_dir}/egocentric/{sample_id}_r{robot_id}.png"
|
| 346 |
+
ego_img.save(ego_path)
|
| 347 |
+
ego_paths[robot_id] = ego_path
|
| 348 |
+
|
| 349 |
+
# --- SFT records ---
|
| 350 |
+
if topdown_path:
|
| 351 |
+
self.sft_records.append({
|
| 352 |
+
"id": f"{sample_id}_topdown",
|
| 353 |
+
"image": topdown_path,
|
| 354 |
+
"view": "topdown",
|
| 355 |
+
"conversations": [
|
| 356 |
+
{"role": "system", "content": self.config.SFT_SYSTEM_PROMPT},
|
| 357 |
+
{"role": "user", "content": (
|
| 358 |
+
f"<image>\nAnalyze this disaster rescue scenario at step {step}. "
|
| 359 |
+
f"{rescued} survivors have been rescued so far. "
|
| 360 |
+
f"Provide your physical reasoning about the current situation, "
|
| 361 |
+
f"flood dynamics, and recommended robot actions."
|
| 362 |
+
)},
|
| 363 |
+
{"role": "assistant", "content": chain["full_chain"]},
|
| 364 |
+
],
|
| 365 |
+
"metadata": {
|
| 366 |
+
"scenario_id": scenario_id, "step": step, "rescued": rescued,
|
| 367 |
+
"num_survivors": chain["num_survivors_remaining"],
|
| 368 |
+
"num_hazards": chain["num_hazard_cells"],
|
| 369 |
+
"scan_radius": scan_radius, "priority_sectors": priority_sectors,
|
| 370 |
+
},
|
| 371 |
+
})
|
| 372 |
+
|
| 373 |
+
for robot_id, ego_path in ego_paths.items():
|
| 374 |
+
agent_pos = agents[robot_id]
|
| 375 |
+
self.sft_records.append({
|
| 376 |
+
"id": f"{sample_id}_ego_r{robot_id}",
|
| 377 |
+
"image": ego_path,
|
| 378 |
+
"view": "egocentric",
|
| 379 |
+
"robot_id": robot_id,
|
| 380 |
+
"conversations": [
|
| 381 |
+
{"role": "system", "content": self.config.SFT_SYSTEM_PROMPT},
|
| 382 |
+
{"role": "user", "content": (
|
| 383 |
+
f"<image>\nYou are Robot {robot_id} at position ({agent_pos[0]},{agent_pos[1]}) "
|
| 384 |
+
f"in sector {get_sector_for_cell(agent_pos[0], agent_pos[1])}. "
|
| 385 |
+
f"This is your egocentric view with scan radius {scan_radius}. "
|
| 386 |
+
f"Analyze what you see and recommend your next action."
|
| 387 |
+
)},
|
| 388 |
+
{"role": "assistant", "content": chain["full_chain"]},
|
| 389 |
+
],
|
| 390 |
+
"metadata": {
|
| 391 |
+
"scenario_id": scenario_id, "step": step,
|
| 392 |
+
"robot_id": robot_id, "robot_pos": list(agent_pos),
|
| 393 |
+
"scan_radius": scan_radius,
|
| 394 |
+
},
|
| 395 |
+
})
|
| 396 |
+
|
| 397 |
+
return {"sample_id": sample_id, "topdown": topdown_path, "egocentric": ego_paths, "chain": chain_path}
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
# ============================================================
|
| 401 |
+
# MAIN
|
| 402 |
+
# ============================================================
|
| 403 |
+
def main():
|
| 404 |
+
import argparse
|
| 405 |
+
parser = argparse.ArgumentParser(description="AEGIS Batch Data Generator")
|
| 406 |
+
parser.add_argument("--output", default="aegis_dataset", help="Output directory")
|
| 407 |
+
parser.add_argument("--seeds", type=int, default=40, help="Number of seeds")
|
| 408 |
+
parser.add_argument("--quick", action="store_true", help="Quick mode: 5 seeds, top-down only")
|
| 409 |
+
parser.add_argument("--no-ego", action="store_true", help="Skip egocentric frames")
|
| 410 |
+
parser.add_argument("--all-robots", action="store_true", help="Ego frames for all 3 robots")
|
| 411 |
+
args = parser.parse_args()
|
| 412 |
+
|
| 413 |
+
config = DatasetConfig()
|
| 414 |
+
config.OUTPUT_DIR = args.output
|
| 415 |
+
|
| 416 |
+
if args.quick:
|
| 417 |
+
config.SEEDS = list(range(1, 6))
|
| 418 |
+
config.RENDER_EGOCENTRIC = False
|
| 419 |
+
print("[QUICK MODE] 5 seeds, top-down only\n")
|
| 420 |
+
else:
|
| 421 |
+
config.SEEDS = list(range(1, args.seeds + 1))
|
| 422 |
+
|
| 423 |
+
if args.no_ego:
|
| 424 |
+
config.RENDER_EGOCENTRIC = False
|
| 425 |
+
if args.all_robots:
|
| 426 |
+
config.RENDER_EGO_ROBOTS = [0, 1, 2]
|
| 427 |
+
|
| 428 |
+
generator = AEGISBatchGenerator(config)
|
| 429 |
+
manifest = generator.generate_all()
|
| 430 |
+
return manifest
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
if __name__ == "__main__":
|
| 434 |
+
main()
|
aegis-reason/aegis-reason/aegis_dataloader.py
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS Custom Dataloader for cosmos-rl SFT
|
| 3 |
+
==========================================
|
| 4 |
+
Custom data loading script for cosmos-rl that handles our AEGIS
|
| 5 |
+
image-based disaster rescue reasoning dataset.
|
| 6 |
+
|
| 7 |
+
This replaces the default LLaVA dataloader with AEGIS-specific
|
| 8 |
+
image loading, conversation formatting, and data augmentation.
|
| 9 |
+
|
| 10 |
+
Usage with cosmos-rl:
|
| 11 |
+
cosmos-rl --config aegis_sft.toml aegis_dataloader.py
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
import logging
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from typing import Dict, List, Optional, Any
|
| 19 |
+
|
| 20 |
+
import torch
|
| 21 |
+
from torch.utils.data import Dataset
|
| 22 |
+
from PIL import Image
|
| 23 |
+
|
| 24 |
+
logger = logging.getLogger(__name__)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class CosmosSFTDataset(Dataset):
|
| 28 |
+
"""AEGIS dataset for Cosmos Reason 2 SFT via cosmos-rl.
|
| 29 |
+
|
| 30 |
+
Loads LLaVA-format annotations with image paths and conversation pairs.
|
| 31 |
+
Handles image loading, tokenization, and formatting for the Qwen3-VL
|
| 32 |
+
architecture that underlies Cosmos Reason 2.
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
def setup(self, config, tokenizer, *args, **kwargs):
|
| 36 |
+
"""Called by cosmos-rl launcher after mounting the dataset.
|
| 37 |
+
|
| 38 |
+
Args:
|
| 39 |
+
config: cosmos-rl Config object with custom.dataset settings
|
| 40 |
+
tokenizer: AutoTokenizer for the model
|
| 41 |
+
"""
|
| 42 |
+
self.config = config
|
| 43 |
+
self.tokenizer = tokenizer
|
| 44 |
+
|
| 45 |
+
# Load paths from config
|
| 46 |
+
annotation_path = config.custom.dataset.annotation_path
|
| 47 |
+
self.media_path = config.custom.dataset.media_path or ""
|
| 48 |
+
|
| 49 |
+
# Vision settings
|
| 50 |
+
self.min_pixels = getattr(config.custom.vision, 'min_pixels', 3136)
|
| 51 |
+
self.max_pixels = getattr(config.custom.vision, 'max_pixels', 409600)
|
| 52 |
+
|
| 53 |
+
# Load annotations
|
| 54 |
+
logger.info(f"Loading AEGIS annotations from {annotation_path}")
|
| 55 |
+
with open(annotation_path, 'r') as f:
|
| 56 |
+
self.annotations = json.load(f)
|
| 57 |
+
logger.info(f"Loaded {len(self.annotations)} training samples")
|
| 58 |
+
|
| 59 |
+
# Validate a sample
|
| 60 |
+
if self.annotations:
|
| 61 |
+
sample = self.annotations[0]
|
| 62 |
+
logger.info(f"Sample entry: id={sample['id']}, "
|
| 63 |
+
f"image={sample.get('image', 'N/A')}, "
|
| 64 |
+
f"turns={len(sample.get('conversations', []))}")
|
| 65 |
+
|
| 66 |
+
def __len__(self) -> int:
|
| 67 |
+
return len(self.annotations)
|
| 68 |
+
|
| 69 |
+
def __getitem__(self, idx: int) -> Dict[str, Any]:
|
| 70 |
+
"""Return a single training sample.
|
| 71 |
+
|
| 72 |
+
Returns dict with:
|
| 73 |
+
- id: sample identifier
|
| 74 |
+
- image: PIL Image or path
|
| 75 |
+
- conversations: list of {from, value} turns
|
| 76 |
+
"""
|
| 77 |
+
entry = self.annotations[idx]
|
| 78 |
+
|
| 79 |
+
# Build full image path
|
| 80 |
+
image_rel = entry.get("image", "")
|
| 81 |
+
if self.media_path and not os.path.isabs(image_rel):
|
| 82 |
+
image_path = os.path.join(self.media_path, image_rel)
|
| 83 |
+
else:
|
| 84 |
+
image_path = image_rel
|
| 85 |
+
|
| 86 |
+
# Load and validate image
|
| 87 |
+
try:
|
| 88 |
+
image = Image.open(image_path).convert("RGB")
|
| 89 |
+
except Exception as e:
|
| 90 |
+
logger.warning(f"Failed to load image {image_path}: {e}. Using blank.")
|
| 91 |
+
image = Image.new("RGB", (640, 640), (0, 0, 0))
|
| 92 |
+
|
| 93 |
+
# Return in cosmos-rl expected format
|
| 94 |
+
return {
|
| 95 |
+
"id": entry["id"],
|
| 96 |
+
"image": image_path, # cosmos-rl handles image loading internally
|
| 97 |
+
"conversations": entry["conversations"],
|
| 98 |
+
}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# cosmos-rl discovers the dataset class by this module-level variable
|
| 102 |
+
dataset = CosmosSFTDataset
|
aegis-reason/aegis-reason/aegis_grpo_reward.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS GRPO Reward Function for cosmos-rl
|
| 3 |
+
==========================================
|
| 4 |
+
Custom reward function that scores model generations using the VARP
|
| 5 |
+
framework (Visual-Action Reasoning Precision) against simulation oracle
|
| 6 |
+
ground truth.
|
| 7 |
+
|
| 8 |
+
The reward function decomposes into:
|
| 9 |
+
1. VARP composite score (spatial + temporal + causal + decision)
|
| 10 |
+
2. Format bonus for structured [SECTION] output
|
| 11 |
+
3. Brevity penalty for overly terse responses
|
| 12 |
+
4. Completeness bonus for mentioning all 4 reasoning components
|
| 13 |
+
|
| 14 |
+
This replaces the standard reward model with a deterministic,
|
| 15 |
+
simulation-grounded reward signal — key advantage of synthetic data.
|
| 16 |
+
|
| 17 |
+
Usage with cosmos-rl:
|
| 18 |
+
cosmos-rl --config aegis_grpo.toml aegis_grpo_reward.py
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import json
|
| 22 |
+
import os
|
| 23 |
+
import re
|
| 24 |
+
import logging
|
| 25 |
+
from typing import Dict, List, Any, Optional
|
| 26 |
+
|
| 27 |
+
import torch
|
| 28 |
+
from torch.utils.data import Dataset
|
| 29 |
+
|
| 30 |
+
logger = logging.getLogger(__name__)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# ============================================================
|
| 34 |
+
# VARP REWARD COMPONENTS (inline for single-file deployment)
|
| 35 |
+
# ============================================================
|
| 36 |
+
|
| 37 |
+
def parse_robots_from_gt(gt_text: str) -> List[Dict]:
|
| 38 |
+
robots = []
|
| 39 |
+
for m in re.finditer(r'Robot (\d+): position \((\d+),(\d+)\)', gt_text):
|
| 40 |
+
robots.append({"id": int(m.group(1)), "pos": [int(m.group(2)), int(m.group(3))]})
|
| 41 |
+
return robots
|
| 42 |
+
|
| 43 |
+
def parse_survivors_from_gt(gt_text: str) -> List[Dict]:
|
| 44 |
+
survivors = []
|
| 45 |
+
for m in re.finditer(r'Survivor at \((\d+),(\d+)\)', gt_text):
|
| 46 |
+
survivors.append({"pos": [int(m.group(1)), int(m.group(2))]})
|
| 47 |
+
return survivors
|
| 48 |
+
|
| 49 |
+
def score_spatial(prediction: str, gt: Dict) -> float:
|
| 50 |
+
"""Score spatial grounding: entity identification + localization."""
|
| 51 |
+
gt_text = gt.get("spatial_reasoning", "")
|
| 52 |
+
robots = parse_robots_from_gt(gt_text)
|
| 53 |
+
survivors = parse_survivors_from_gt(gt_text)
|
| 54 |
+
|
| 55 |
+
total = len(robots) + len(survivors)
|
| 56 |
+
if total == 0:
|
| 57 |
+
return 1.0
|
| 58 |
+
|
| 59 |
+
found = 0
|
| 60 |
+
for r in robots:
|
| 61 |
+
pos_str = f"({r['pos'][0]},{r['pos'][1]})"
|
| 62 |
+
pos_str2 = f"({r['pos'][0]}, {r['pos'][1]})"
|
| 63 |
+
if pos_str in prediction.replace(" ", "") or pos_str2 in prediction:
|
| 64 |
+
found += 1
|
| 65 |
+
for s in survivors:
|
| 66 |
+
pos_str = f"({s['pos'][0]},{s['pos'][1]})"
|
| 67 |
+
pos_str2 = f"({s['pos'][0]}, {s['pos'][1]})"
|
| 68 |
+
if pos_str in prediction.replace(" ", "") or pos_str2 in prediction:
|
| 69 |
+
found += 1
|
| 70 |
+
|
| 71 |
+
return found / total
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def score_temporal(prediction: str, gt: Dict) -> float:
|
| 75 |
+
"""Score temporal dynamics: flood count + expansion awareness."""
|
| 76 |
+
gt_text = gt.get("temporal_reasoning", "")
|
| 77 |
+
gt_flood_match = re.search(r'Flood cells: (\d+)', gt_text)
|
| 78 |
+
gt_flood = int(gt_flood_match.group(1)) if gt_flood_match else gt.get("num_hazard_cells", 0)
|
| 79 |
+
|
| 80 |
+
# Check if prediction mentions flood count
|
| 81 |
+
pred_flood_match = re.search(r'(\d+)\s*flood\s*cell', prediction, re.IGNORECASE)
|
| 82 |
+
if pred_flood_match:
|
| 83 |
+
pred_flood = int(pred_flood_match.group(1))
|
| 84 |
+
count_score = max(0, 1.0 - abs(pred_flood - gt_flood) / max(gt_flood, 1))
|
| 85 |
+
else:
|
| 86 |
+
count_score = 0.0
|
| 87 |
+
|
| 88 |
+
# Check expansion awareness
|
| 89 |
+
expansion_keywords = ["expand", "spread", "growing", "frontier", "advancing", "flood"]
|
| 90 |
+
expansion_score = 1.0 if any(kw in prediction.lower() for kw in expansion_keywords) else 0.0
|
| 91 |
+
|
| 92 |
+
return 0.6 * count_score + 0.4 * expansion_score
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def score_causal(prediction: str, gt: Dict) -> float:
|
| 96 |
+
"""Score causal reasoning: urgency classification accuracy."""
|
| 97 |
+
gt_text = gt.get("causal_reasoning", "")
|
| 98 |
+
assessments = []
|
| 99 |
+
for m in re.finditer(r'Survivor \((\d+),(\d+)\): urgency (\w+)', gt_text):
|
| 100 |
+
assessments.append({
|
| 101 |
+
"pos": [int(m.group(1)), int(m.group(2))],
|
| 102 |
+
"urgency": m.group(3),
|
| 103 |
+
})
|
| 104 |
+
|
| 105 |
+
if not assessments:
|
| 106 |
+
return 1.0
|
| 107 |
+
|
| 108 |
+
# Isolate causal section if present
|
| 109 |
+
causal_section = prediction
|
| 110 |
+
ci = prediction.upper().find("[CAUSAL")
|
| 111 |
+
if ci >= 0:
|
| 112 |
+
di = prediction.upper().find("[DECISION", ci)
|
| 113 |
+
causal_section = prediction[ci:di] if di > 0 else prediction[ci:]
|
| 114 |
+
|
| 115 |
+
correct = 0
|
| 116 |
+
for a in assessments:
|
| 117 |
+
pattern = rf'\({a["pos"][0]}\s*,\s*{a["pos"][1]}\)'
|
| 118 |
+
match = re.search(pattern, causal_section)
|
| 119 |
+
if match:
|
| 120 |
+
context = causal_section[match.start():match.start() + 300].upper()
|
| 121 |
+
if a["urgency"] in context:
|
| 122 |
+
correct += 1
|
| 123 |
+
|
| 124 |
+
return correct / len(assessments)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
def score_decision(prediction: str, gt: Dict) -> float:
|
| 128 |
+
"""Score decision quality: assignment match rate."""
|
| 129 |
+
gt_text = gt.get("decision_reasoning", "")
|
| 130 |
+
assignments = []
|
| 131 |
+
for m in re.finditer(r'Robot (\d+) \((\d+),(\d+)\) .* survivor \((\d+),(\d+)\)', gt_text):
|
| 132 |
+
assignments.append({
|
| 133 |
+
"robot_id": int(m.group(1)),
|
| 134 |
+
"target": [int(m.group(4)), int(m.group(5))],
|
| 135 |
+
})
|
| 136 |
+
|
| 137 |
+
if not assignments:
|
| 138 |
+
return 1.0
|
| 139 |
+
|
| 140 |
+
# Isolate decision section
|
| 141 |
+
dec_section = prediction
|
| 142 |
+
di = prediction.upper().find("[DECISION")
|
| 143 |
+
if di >= 0:
|
| 144 |
+
dec_section = prediction[di:]
|
| 145 |
+
|
| 146 |
+
matches = 0
|
| 147 |
+
for a in assignments:
|
| 148 |
+
robot_pat = rf'Robot\s*{a["robot_id"]}'
|
| 149 |
+
target_str = f"({a['target'][0]},{a['target'][1]})"
|
| 150 |
+
for rmatch in re.finditer(robot_pat, dec_section, re.IGNORECASE):
|
| 151 |
+
ctx = dec_section[rmatch.start():rmatch.start() + 200]
|
| 152 |
+
if target_str.replace(" ", "") in ctx.replace(" ", ""):
|
| 153 |
+
matches += 1
|
| 154 |
+
break
|
| 155 |
+
|
| 156 |
+
return matches / len(assignments)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def compute_varp_reward(prediction: str, gt: Dict, config: Dict) -> float:
|
| 160 |
+
"""Compute the full VARP reward signal for GRPO."""
|
| 161 |
+
|
| 162 |
+
# Axis scores
|
| 163 |
+
s_spatial = score_spatial(prediction, gt)
|
| 164 |
+
s_temporal = score_temporal(prediction, gt)
|
| 165 |
+
s_causal = score_causal(prediction, gt)
|
| 166 |
+
s_decision = score_decision(prediction, gt)
|
| 167 |
+
|
| 168 |
+
# Weighted VARP composite
|
| 169 |
+
w = config
|
| 170 |
+
varp = (
|
| 171 |
+
w.get("spatial_weight", 0.30) * s_spatial +
|
| 172 |
+
w.get("temporal_weight", 0.20) * s_temporal +
|
| 173 |
+
w.get("causal_weight", 0.25) * s_causal +
|
| 174 |
+
w.get("decision_weight", 0.25) * s_decision
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
# Format bonus: reward structured output with section headers
|
| 178 |
+
sections = ["[SPATIAL", "[TEMPORAL", "[CAUSAL", "[DECISION"]
|
| 179 |
+
sections_found = sum(1 for s in sections if s in prediction.upper())
|
| 180 |
+
format_bonus = w.get("format_bonus", 0.1) * (sections_found / 4)
|
| 181 |
+
|
| 182 |
+
# Brevity penalty
|
| 183 |
+
brevity = w.get("brevity_penalty", -0.3) if len(prediction) < 100 else 0.0
|
| 184 |
+
|
| 185 |
+
# Completeness bonus: all 4 components present
|
| 186 |
+
completeness = 0.1 if sections_found == 4 else 0.0
|
| 187 |
+
|
| 188 |
+
total_reward = varp + format_bonus + brevity + completeness
|
| 189 |
+
|
| 190 |
+
# Clamp to [-1, 1.5] range for GRPO stability
|
| 191 |
+
return max(-1.0, min(1.5, total_reward))
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
# ============================================================
|
| 195 |
+
# cosmos-rl GRPO Dataset + Reward Interface
|
| 196 |
+
# ============================================================
|
| 197 |
+
|
| 198 |
+
class CosmosSFTDataset(Dataset):
|
| 199 |
+
"""AEGIS GRPO dataset with integrated reward computation."""
|
| 200 |
+
|
| 201 |
+
def setup(self, config, tokenizer, *args, **kwargs):
|
| 202 |
+
"""Called by cosmos-rl launcher."""
|
| 203 |
+
self.config = config
|
| 204 |
+
self.tokenizer = tokenizer
|
| 205 |
+
self.media_path = config.custom.dataset.media_path or ""
|
| 206 |
+
|
| 207 |
+
# Load annotations
|
| 208 |
+
annotation_path = config.custom.dataset.annotation_path
|
| 209 |
+
with open(annotation_path, 'r') as f:
|
| 210 |
+
self.annotations = json.load(f)
|
| 211 |
+
logger.info(f"AEGIS GRPO: Loaded {len(self.annotations)} prompts")
|
| 212 |
+
|
| 213 |
+
# Load ground truth chains for reward computation
|
| 214 |
+
self.chains_dir = getattr(config.custom.reward, 'chains_dir', '')
|
| 215 |
+
self.reward_config = {
|
| 216 |
+
"spatial_weight": getattr(config.custom.reward, 'spatial_weight', 0.30),
|
| 217 |
+
"temporal_weight": getattr(config.custom.reward, 'temporal_weight', 0.20),
|
| 218 |
+
"causal_weight": getattr(config.custom.reward, 'causal_weight', 0.25),
|
| 219 |
+
"decision_weight": getattr(config.custom.reward, 'decision_weight', 0.25),
|
| 220 |
+
"format_bonus": getattr(config.custom.reward, 'format_bonus', 0.1),
|
| 221 |
+
"brevity_penalty": getattr(config.custom.reward, 'brevity_penalty', -0.3),
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
# Pre-load all ground truth chains into memory
|
| 225 |
+
self.gt_chains = {}
|
| 226 |
+
if self.chains_dir and os.path.isdir(self.chains_dir):
|
| 227 |
+
for fn in os.listdir(self.chains_dir):
|
| 228 |
+
if fn.endswith('.json'):
|
| 229 |
+
key = fn.replace('.json', '')
|
| 230 |
+
with open(os.path.join(self.chains_dir, fn)) as f:
|
| 231 |
+
self.gt_chains[key] = json.load(f)
|
| 232 |
+
logger.info(f"AEGIS GRPO: Loaded {len(self.gt_chains)} ground truth chains")
|
| 233 |
+
|
| 234 |
+
def __len__(self):
|
| 235 |
+
return len(self.annotations)
|
| 236 |
+
|
| 237 |
+
def __getitem__(self, idx):
|
| 238 |
+
entry = self.annotations[idx]
|
| 239 |
+
image_rel = entry.get("image", "")
|
| 240 |
+
if self.media_path and not os.path.isabs(image_rel):
|
| 241 |
+
image_path = os.path.join(self.media_path, image_rel)
|
| 242 |
+
else:
|
| 243 |
+
image_path = image_rel
|
| 244 |
+
|
| 245 |
+
return {
|
| 246 |
+
"id": entry["id"],
|
| 247 |
+
"image": image_path,
|
| 248 |
+
"conversations": entry["conversations"],
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
def compute_reward(self, sample_id: str, generation: str) -> float:
|
| 252 |
+
"""Compute VARP-based reward for a model generation.
|
| 253 |
+
|
| 254 |
+
Called by cosmos-rl GRPO trainer for each (prompt, generation) pair.
|
| 255 |
+
|
| 256 |
+
Args:
|
| 257 |
+
sample_id: Dataset sample identifier (e.g., "seed002_b2.0_no_intel_step006_topdown")
|
| 258 |
+
generation: Model-generated text response
|
| 259 |
+
|
| 260 |
+
Returns:
|
| 261 |
+
float reward in [-1, 1.5] range
|
| 262 |
+
"""
|
| 263 |
+
# Derive chain key from sample ID
|
| 264 |
+
chain_key = sample_id
|
| 265 |
+
for suffix in ["_topdown", "_egocentric", "_ego_r0", "_ego_r1", "_ego_r2"]:
|
| 266 |
+
chain_key = chain_key.replace(suffix, "")
|
| 267 |
+
|
| 268 |
+
gt = self.gt_chains.get(chain_key)
|
| 269 |
+
if gt is None:
|
| 270 |
+
# Fallback: format-only reward if no GT available
|
| 271 |
+
sections = ["[SPATIAL", "[TEMPORAL", "[CAUSAL", "[DECISION"]
|
| 272 |
+
sections_found = sum(1 for s in sections if s in generation.upper())
|
| 273 |
+
return 0.1 * (sections_found / 4) + (-0.3 if len(generation) < 100 else 0.0)
|
| 274 |
+
|
| 275 |
+
return compute_varp_reward(generation, gt, self.reward_config)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
# cosmos-rl discovers this
|
| 279 |
+
dataset = CosmosSFTDataset
|
aegis-reason/aegis-reason/aegis_inference.py
ADDED
|
@@ -0,0 +1,344 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS-Reason Inference — Test fine-tuned Cosmos Reason 2 on disaster frames
|
| 3 |
+
============================================================================
|
| 4 |
+
After SFT training, use this script to:
|
| 5 |
+
1. Load the fine-tuned checkpoint
|
| 6 |
+
2. Feed disaster rescue frames
|
| 7 |
+
3. Get structured reasoning chains
|
| 8 |
+
|
| 9 |
+
Supports:
|
| 10 |
+
- Single image inference
|
| 11 |
+
- Batch inference on a directory of images
|
| 12 |
+
- Comparison mode (base model vs fine-tuned)
|
| 13 |
+
- JSON output for downstream evaluation
|
| 14 |
+
|
| 15 |
+
Usage:
|
| 16 |
+
# Single image
|
| 17 |
+
python aegis_inference.py --checkpoint /path/to/ckpt --image frame.png
|
| 18 |
+
|
| 19 |
+
# Batch inference on all topdown frames
|
| 20 |
+
python aegis_inference.py --checkpoint /path/to/ckpt --image-dir aegis_dataset/topdown/ --max-images 50
|
| 21 |
+
|
| 22 |
+
# Zero-shot (no checkpoint, base model only)
|
| 23 |
+
python aegis_inference.py --model nvidia/Cosmos-Reason2-2B --image frame.png
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
import argparse
|
| 27 |
+
import json
|
| 28 |
+
import os
|
| 29 |
+
import time
|
| 30 |
+
import glob
|
| 31 |
+
from pathlib import Path
|
| 32 |
+
from typing import Optional, List, Dict
|
| 33 |
+
|
| 34 |
+
import torch
|
| 35 |
+
from transformers import AutoProcessor, AutoModelForImageTextToText
|
| 36 |
+
from PIL import Image
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# ============================================================
|
| 40 |
+
# AEGIS SYSTEM PROMPT
|
| 41 |
+
# ============================================================
|
| 42 |
+
AEGIS_SYSTEM_PROMPT = (
|
| 43 |
+
"You are AEGIS-Reason, a physical AI reasoning model for disaster rescue coordination. "
|
| 44 |
+
"Given a visual frame from a 20x20 grid disaster simulation, provide detailed "
|
| 45 |
+
"chain-of-thought reasoning about: (1) spatial grounding - identify and locate all "
|
| 46 |
+
"entities (robots, survivors, flood zones), (2) temporal dynamics - predict flood "
|
| 47 |
+
"expansion, (3) causal reasoning - determine rescue urgency based on threat proximity "
|
| 48 |
+
"and robot distances, (4) decision - recommend optimal robot-to-survivor assignments."
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# ============================================================
|
| 53 |
+
# MODEL LOADER
|
| 54 |
+
# ============================================================
|
| 55 |
+
class AEGISReason:
|
| 56 |
+
"""Wrapper for Cosmos Reason 2 inference with AEGIS fine-tuning."""
|
| 57 |
+
|
| 58 |
+
def __init__(
|
| 59 |
+
self,
|
| 60 |
+
model_name: str = "nvidia/Cosmos-Reason2-2B",
|
| 61 |
+
checkpoint: Optional[str] = None,
|
| 62 |
+
device: str = "cuda",
|
| 63 |
+
max_new_tokens: int = 1024,
|
| 64 |
+
enable_thinking: bool = True,
|
| 65 |
+
):
|
| 66 |
+
self.device = device
|
| 67 |
+
self.max_new_tokens = max_new_tokens
|
| 68 |
+
self.enable_thinking = enable_thinking
|
| 69 |
+
|
| 70 |
+
print(f"Loading model: {model_name}")
|
| 71 |
+
if checkpoint:
|
| 72 |
+
print(f" + Fine-tuned checkpoint: {checkpoint}")
|
| 73 |
+
|
| 74 |
+
# Load processor
|
| 75 |
+
self.processor = AutoProcessor.from_pretrained(
|
| 76 |
+
model_name,
|
| 77 |
+
trust_remote_code=True,
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
# Load model (with optional checkpoint overlay)
|
| 81 |
+
model_path = checkpoint if checkpoint else model_name
|
| 82 |
+
self.model = AutoModelForImageTextToText.from_pretrained(
|
| 83 |
+
model_path,
|
| 84 |
+
torch_dtype=torch.bfloat16,
|
| 85 |
+
device_map="auto",
|
| 86 |
+
trust_remote_code=True,
|
| 87 |
+
)
|
| 88 |
+
self.model.eval()
|
| 89 |
+
print(f" Model loaded on {device}")
|
| 90 |
+
|
| 91 |
+
def infer(
|
| 92 |
+
self,
|
| 93 |
+
image_path: str,
|
| 94 |
+
user_prompt: Optional[str] = None,
|
| 95 |
+
step: int = 0,
|
| 96 |
+
rescued: int = 0,
|
| 97 |
+
) -> Dict:
|
| 98 |
+
"""Run inference on a single disaster frame.
|
| 99 |
+
|
| 100 |
+
Args:
|
| 101 |
+
image_path: Path to the 640x640 disaster frame
|
| 102 |
+
user_prompt: Custom user prompt (default: standard AEGIS prompt)
|
| 103 |
+
step: Simulation step number (for context)
|
| 104 |
+
rescued: Number of survivors rescued so far
|
| 105 |
+
|
| 106 |
+
Returns:
|
| 107 |
+
Dict with: response, thinking (if enabled), latency_ms
|
| 108 |
+
"""
|
| 109 |
+
# Load image
|
| 110 |
+
image = Image.open(image_path).convert("RGB")
|
| 111 |
+
|
| 112 |
+
# Build prompt
|
| 113 |
+
if user_prompt is None:
|
| 114 |
+
user_prompt = (
|
| 115 |
+
f"Analyze this disaster rescue scenario at step {step}. "
|
| 116 |
+
f"{rescued} survivors have been rescued so far. "
|
| 117 |
+
f"Provide your physical reasoning about the current situation, "
|
| 118 |
+
f"flood dynamics, and recommended robot actions."
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# Build messages in Qwen3-VL chat format
|
| 122 |
+
messages = [
|
| 123 |
+
{
|
| 124 |
+
"role": "system",
|
| 125 |
+
"content": AEGIS_SYSTEM_PROMPT,
|
| 126 |
+
},
|
| 127 |
+
{
|
| 128 |
+
"role": "user",
|
| 129 |
+
"content": [
|
| 130 |
+
{"type": "image", "image": image},
|
| 131 |
+
{"type": "text", "text": user_prompt},
|
| 132 |
+
],
|
| 133 |
+
},
|
| 134 |
+
]
|
| 135 |
+
|
| 136 |
+
# Process with Cosmos Reason 2 processor
|
| 137 |
+
text = self.processor.apply_chat_template(
|
| 138 |
+
messages,
|
| 139 |
+
tokenize=False,
|
| 140 |
+
add_generation_prompt=True,
|
| 141 |
+
enable_thinking=self.enable_thinking,
|
| 142 |
+
)
|
| 143 |
+
inputs = self.processor(
|
| 144 |
+
text=[text],
|
| 145 |
+
images=[image],
|
| 146 |
+
return_tensors="pt",
|
| 147 |
+
padding=True,
|
| 148 |
+
).to(self.device)
|
| 149 |
+
|
| 150 |
+
# Generate
|
| 151 |
+
start_time = time.time()
|
| 152 |
+
with torch.no_grad():
|
| 153 |
+
output_ids = self.model.generate(
|
| 154 |
+
**inputs,
|
| 155 |
+
max_new_tokens=self.max_new_tokens,
|
| 156 |
+
do_sample=False, # Greedy for deterministic reasoning
|
| 157 |
+
)
|
| 158 |
+
|
| 159 |
+
latency_ms = (time.time() - start_time) * 1000
|
| 160 |
+
|
| 161 |
+
# Decode
|
| 162 |
+
# Remove input tokens from output
|
| 163 |
+
generated_ids = output_ids[0][inputs["input_ids"].shape[1]:]
|
| 164 |
+
response = self.processor.decode(generated_ids, skip_special_tokens=True)
|
| 165 |
+
|
| 166 |
+
# Parse thinking vs response if thinking is enabled
|
| 167 |
+
thinking = ""
|
| 168 |
+
final_response = response
|
| 169 |
+
if self.enable_thinking and "<think>" in response:
|
| 170 |
+
parts = response.split("</think>")
|
| 171 |
+
if len(parts) >= 2:
|
| 172 |
+
thinking = parts[0].replace("<think>", "").strip()
|
| 173 |
+
final_response = parts[1].strip()
|
| 174 |
+
|
| 175 |
+
return {
|
| 176 |
+
"image": image_path,
|
| 177 |
+
"response": final_response,
|
| 178 |
+
"thinking": thinking,
|
| 179 |
+
"latency_ms": round(latency_ms, 1),
|
| 180 |
+
"tokens_generated": len(generated_ids),
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
# ============================================================
|
| 185 |
+
# BATCH INFERENCE
|
| 186 |
+
# ============================================================
|
| 187 |
+
def batch_infer(
|
| 188 |
+
model: AEGISReason,
|
| 189 |
+
image_paths: List[str],
|
| 190 |
+
output_path: Optional[str] = None,
|
| 191 |
+
) -> List[Dict]:
|
| 192 |
+
"""Run inference on a batch of images."""
|
| 193 |
+
results = []
|
| 194 |
+
total = len(image_paths)
|
| 195 |
+
|
| 196 |
+
for i, path in enumerate(image_paths):
|
| 197 |
+
print(f" [{i+1}/{total}] {os.path.basename(path)}...", end=" ", flush=True)
|
| 198 |
+
|
| 199 |
+
try:
|
| 200 |
+
result = model.infer(image_path=path)
|
| 201 |
+
results.append(result)
|
| 202 |
+
print(f"OK ({result['latency_ms']:.0f}ms, {result['tokens_generated']} tokens)")
|
| 203 |
+
except Exception as e:
|
| 204 |
+
print(f"ERROR: {e}")
|
| 205 |
+
results.append({"image": path, "error": str(e)})
|
| 206 |
+
|
| 207 |
+
# Save results
|
| 208 |
+
if output_path:
|
| 209 |
+
with open(output_path, "w") as f:
|
| 210 |
+
json.dump(results, f, indent=2)
|
| 211 |
+
print(f"\n Results saved to: {output_path}")
|
| 212 |
+
|
| 213 |
+
# Summary
|
| 214 |
+
successful = [r for r in results if "error" not in r]
|
| 215 |
+
if successful:
|
| 216 |
+
avg_latency = sum(r["latency_ms"] for r in successful) / len(successful)
|
| 217 |
+
avg_tokens = sum(r["tokens_generated"] for r in successful) / len(successful)
|
| 218 |
+
print(f"\n Summary: {len(successful)}/{total} successful")
|
| 219 |
+
print(f" Avg latency: {avg_latency:.0f}ms")
|
| 220 |
+
print(f" Avg tokens: {avg_tokens:.0f}")
|
| 221 |
+
|
| 222 |
+
return results
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
# ============================================================
|
| 226 |
+
# EVALUATION — Compare base vs fine-tuned
|
| 227 |
+
# ============================================================
|
| 228 |
+
def evaluate_reasoning_quality(response: str) -> Dict:
|
| 229 |
+
"""Quick heuristic evaluation of reasoning chain quality.
|
| 230 |
+
|
| 231 |
+
Checks for presence of the 4 required reasoning components
|
| 232 |
+
and basic structural quality signals.
|
| 233 |
+
"""
|
| 234 |
+
components = {
|
| 235 |
+
"spatial_grounding": "[SPATIAL GROUNDING]" in response or "spatial" in response.lower(),
|
| 236 |
+
"temporal_dynamics": "[TEMPORAL DYNAMICS]" in response or "temporal" in response.lower() or "flood" in response.lower(),
|
| 237 |
+
"causal_reasoning": "[CAUSAL REASONING]" in response or "urgency" in response.lower() or "causal" in response.lower(),
|
| 238 |
+
"decision": "[DECISION]" in response or "recommend" in response.lower() or "robot" in response.lower(),
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
score = sum(components.values()) / 4.0
|
| 242 |
+
|
| 243 |
+
return {
|
| 244 |
+
"components_present": components,
|
| 245 |
+
"component_score": score,
|
| 246 |
+
"response_length": len(response),
|
| 247 |
+
"has_coordinates": "(" in response and ")" in response and "," in response,
|
| 248 |
+
"has_sector_refs": "sector" in response.lower(),
|
| 249 |
+
"has_distance_refs": "distance" in response.lower() or "steps" in response.lower(),
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
# ============================================================
|
| 254 |
+
# MAIN
|
| 255 |
+
# ============================================================
|
| 256 |
+
def main():
|
| 257 |
+
parser = argparse.ArgumentParser(description="AEGIS-Reason Inference")
|
| 258 |
+
parser.add_argument("--model", default="nvidia/Cosmos-Reason2-2B",
|
| 259 |
+
help="Base model name")
|
| 260 |
+
parser.add_argument("--checkpoint", default=None,
|
| 261 |
+
help="Path to fine-tuned checkpoint")
|
| 262 |
+
parser.add_argument("--image", default=None,
|
| 263 |
+
help="Single image path for inference")
|
| 264 |
+
parser.add_argument("--image-dir", default=None,
|
| 265 |
+
help="Directory of images for batch inference")
|
| 266 |
+
parser.add_argument("--max-images", type=int, default=10,
|
| 267 |
+
help="Max images for batch mode")
|
| 268 |
+
parser.add_argument("--output", default=None,
|
| 269 |
+
help="Output JSON path for results")
|
| 270 |
+
parser.add_argument("--max-tokens", type=int, default=1024,
|
| 271 |
+
help="Max new tokens to generate")
|
| 272 |
+
parser.add_argument("--no-thinking", action="store_true",
|
| 273 |
+
help="Disable thinking/CoT mode")
|
| 274 |
+
parser.add_argument("--evaluate", action="store_true",
|
| 275 |
+
help="Run quality evaluation on responses")
|
| 276 |
+
parser.add_argument("--device", default="cuda",
|
| 277 |
+
help="Device (cuda/cpu)")
|
| 278 |
+
args = parser.parse_args()
|
| 279 |
+
|
| 280 |
+
# Load model
|
| 281 |
+
model = AEGISReason(
|
| 282 |
+
model_name=args.model,
|
| 283 |
+
checkpoint=args.checkpoint,
|
| 284 |
+
device=args.device,
|
| 285 |
+
max_new_tokens=args.max_tokens,
|
| 286 |
+
enable_thinking=not args.no_thinking,
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
# Single image mode
|
| 290 |
+
if args.image:
|
| 291 |
+
print(f"\nInferring on: {args.image}")
|
| 292 |
+
result = model.infer(image_path=args.image)
|
| 293 |
+
|
| 294 |
+
if result.get("thinking"):
|
| 295 |
+
print(f"\n--- Thinking ---")
|
| 296 |
+
print(result["thinking"][:500])
|
| 297 |
+
|
| 298 |
+
print(f"\n--- Response ---")
|
| 299 |
+
print(result["response"])
|
| 300 |
+
print(f"\n[Latency: {result['latency_ms']:.0f}ms | Tokens: {result['tokens_generated']}]")
|
| 301 |
+
|
| 302 |
+
if args.evaluate:
|
| 303 |
+
eval_result = evaluate_reasoning_quality(result["response"])
|
| 304 |
+
print(f"\n--- Evaluation ---")
|
| 305 |
+
print(f" Component score: {eval_result['component_score']:.0%}")
|
| 306 |
+
for comp, present in eval_result["components_present"].items():
|
| 307 |
+
status = "✓" if present else "✗"
|
| 308 |
+
print(f" {status} {comp}")
|
| 309 |
+
|
| 310 |
+
if args.output:
|
| 311 |
+
with open(args.output, "w") as f:
|
| 312 |
+
json.dump(result, f, indent=2)
|
| 313 |
+
print(f"\nSaved to: {args.output}")
|
| 314 |
+
|
| 315 |
+
# Batch mode
|
| 316 |
+
elif args.image_dir:
|
| 317 |
+
image_paths = sorted(glob.glob(os.path.join(args.image_dir, "*.png")))
|
| 318 |
+
if not image_paths:
|
| 319 |
+
image_paths = sorted(glob.glob(os.path.join(args.image_dir, "*.jpg")))
|
| 320 |
+
|
| 321 |
+
image_paths = image_paths[:args.max_images]
|
| 322 |
+
print(f"\nBatch inference: {len(image_paths)} images from {args.image_dir}")
|
| 323 |
+
|
| 324 |
+
output_path = args.output or "aegis_inference_results.json"
|
| 325 |
+
results = batch_infer(model, image_paths, output_path)
|
| 326 |
+
|
| 327 |
+
if args.evaluate:
|
| 328 |
+
print(f"\n--- Batch Evaluation ---")
|
| 329 |
+
scores = []
|
| 330 |
+
for r in results:
|
| 331 |
+
if "response" in r:
|
| 332 |
+
eval_r = evaluate_reasoning_quality(r["response"])
|
| 333 |
+
scores.append(eval_r["component_score"])
|
| 334 |
+
if scores:
|
| 335 |
+
print(f" Avg component score: {sum(scores)/len(scores):.0%}")
|
| 336 |
+
print(f" Perfect scores: {sum(1 for s in scores if s == 1.0)}/{len(scores)}")
|
| 337 |
+
|
| 338 |
+
else:
|
| 339 |
+
parser.print_help()
|
| 340 |
+
print("\nERROR: Provide --image or --image-dir")
|
| 341 |
+
|
| 342 |
+
|
| 343 |
+
if __name__ == "__main__":
|
| 344 |
+
main()
|
aegis-reason/aegis-reason/aegis_render_engine.py
ADDED
|
@@ -0,0 +1,946 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
AEGIS Render Engine — Autonomous Egocentric Ground Intelligence System
|
| 3 |
+
=======================================================================
|
| 4 |
+
Converts MAELSTROM grid states into visual frames for Cosmos Reason 2.
|
| 5 |
+
|
| 6 |
+
Three output types:
|
| 7 |
+
1. Top-down global frame — full 20×20 grid as seen from above
|
| 8 |
+
2. Egocentric robot frame — per-robot limited-FOV view centered on agent
|
| 9 |
+
3. Ground-truth reasoning chain — structured physical reasoning annotation
|
| 10 |
+
|
| 11 |
+
These outputs form the (frame, reasoning_chain) pairs for:
|
| 12 |
+
- Zero-shot inference (ARGOS mode)
|
| 13 |
+
- SFT post-training dataset (PROMETHEUS mode)
|
| 14 |
+
- Video analytics stream (SENTINEL mode)
|
| 15 |
+
|
| 16 |
+
Design principles:
|
| 17 |
+
- Cell size = 32px → 20×20 grid = 640×640px (Cosmos Reason 2 friendly)
|
| 18 |
+
- High-contrast colors on dark background for VLM readability
|
| 19 |
+
- Minimal text overlays — spatial relationships must be visually parseable
|
| 20 |
+
- Deterministic rendering — same state always produces same frame
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
import numpy as np
|
| 24 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 25 |
+
from typing import Dict, Tuple, List, Optional
|
| 26 |
+
import math
|
| 27 |
+
import json
|
| 28 |
+
import os
|
| 29 |
+
|
| 30 |
+
# ============================================================
|
| 31 |
+
# CONSTANTS
|
| 32 |
+
# ============================================================
|
| 33 |
+
CELL_SIZE = 32 # pixels per grid cell
|
| 34 |
+
GRID_SIZE = 20 # 20×20 grid
|
| 35 |
+
IMG_SIZE = CELL_SIZE * GRID_SIZE # 640×640
|
| 36 |
+
|
| 37 |
+
# Cell type encoding (matches MAELSTROM)
|
| 38 |
+
EMPTY = 0
|
| 39 |
+
HAZARD = 1
|
| 40 |
+
SURVIVOR = 2
|
| 41 |
+
|
| 42 |
+
# Color palette — high contrast for VLM parsing
|
| 43 |
+
COLORS = {
|
| 44 |
+
"background": (13, 13, 13), # #0D0D0D - dark background
|
| 45 |
+
"empty": (45, 48, 52), # #2D3034 - dark grey, navigable
|
| 46 |
+
"hazard": (30, 100, 200), # #1E64C8 - blue flood water
|
| 47 |
+
"hazard_deep": (20, 60, 160), # #143CA0 - deeper flood
|
| 48 |
+
"survivor": (255, 50, 50), # #FF3232 - bright red
|
| 49 |
+
"survivor_glow": (255, 80, 80, 60), # red glow (with alpha)
|
| 50 |
+
"robot": (0, 200, 100), # #00C864 - green robot
|
| 51 |
+
"robot_border": (255, 255, 255), # white border
|
| 52 |
+
"fog": (8, 8, 8), # near-black fog of war
|
| 53 |
+
"grid_line": (60, 60, 60), # subtle grid lines
|
| 54 |
+
"sector_line": (100, 100, 100), # sector boundaries
|
| 55 |
+
"sector_priority":(0, 255, 255), # cyan priority sector
|
| 56 |
+
"scan_radius": (0, 255, 255, 40), # cyan scan circle (alpha)
|
| 57 |
+
"flood_frontier": (0, 200, 255, 80), # flood edge highlight
|
| 58 |
+
"text_white": (255, 255, 255),
|
| 59 |
+
"text_cyan": (0, 255, 255),
|
| 60 |
+
"text_red": (255, 80, 80),
|
| 61 |
+
"assignment_line": (0, 255, 255, 120),# cyan dashed target line
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
# Sector map (matches MAELSTROM)
|
| 65 |
+
SECTOR_GRID = {}
|
| 66 |
+
for sec in range(1, 17):
|
| 67 |
+
rb = (sec - 1) // 4
|
| 68 |
+
cb = (sec - 1) % 4
|
| 69 |
+
SECTOR_GRID[sec] = (rb * 5, rb * 5 + 5, cb * 5, cb * 5 + 5)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def get_sector_for_cell(r: int, c: int) -> int:
|
| 73 |
+
return min(r // 5, 3) * 4 + min(c // 5, 3) + 1
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# ============================================================
|
| 77 |
+
# TOP-DOWN GLOBAL FRAME RENDERER
|
| 78 |
+
# ============================================================
|
| 79 |
+
class TopDownRenderer:
|
| 80 |
+
"""Renders the full 20×20 grid as a top-down image.
|
| 81 |
+
|
| 82 |
+
This is the 'omniscient camera' view — shows ground truth state
|
| 83 |
+
of the entire environment. Used for:
|
| 84 |
+
- Global scene understanding by Cosmos Reason 2
|
| 85 |
+
- Training data where the model must identify all entities
|
| 86 |
+
- Evaluation of spatial reasoning accuracy
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
def __init__(self, cell_size: int = CELL_SIZE):
|
| 90 |
+
self.cell_size = cell_size
|
| 91 |
+
self.img_size = cell_size * GRID_SIZE
|
| 92 |
+
self._try_load_font()
|
| 93 |
+
|
| 94 |
+
def _try_load_font(self):
|
| 95 |
+
"""Load a monospace font for labels."""
|
| 96 |
+
self.font_small = None
|
| 97 |
+
self.font_medium = None
|
| 98 |
+
self.font_large = None
|
| 99 |
+
try:
|
| 100 |
+
# Try common system fonts
|
| 101 |
+
for path in [
|
| 102 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",
|
| 103 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
| 104 |
+
"/usr/share/fonts/truetype/liberation/LiberationMono-Regular.ttf",
|
| 105 |
+
]:
|
| 106 |
+
if os.path.exists(path):
|
| 107 |
+
self.font_small = ImageFont.truetype(path, 10)
|
| 108 |
+
self.font_medium = ImageFont.truetype(path, 14)
|
| 109 |
+
self.font_large = ImageFont.truetype(path, 18)
|
| 110 |
+
break
|
| 111 |
+
except Exception:
|
| 112 |
+
pass
|
| 113 |
+
if self.font_small is None:
|
| 114 |
+
self.font_small = ImageFont.load_default()
|
| 115 |
+
self.font_medium = ImageFont.load_default()
|
| 116 |
+
self.font_large = ImageFont.load_default()
|
| 117 |
+
|
| 118 |
+
def render(
|
| 119 |
+
self,
|
| 120 |
+
grid: np.ndarray,
|
| 121 |
+
agent_positions: Dict[int, Tuple[int, int]],
|
| 122 |
+
step: int = 0,
|
| 123 |
+
rescued: int = 0,
|
| 124 |
+
priority_sectors: List[int] = None,
|
| 125 |
+
assignments: Dict[int, Optional[Tuple[int, int]]] = None,
|
| 126 |
+
scan_radius: int = 5,
|
| 127 |
+
flood_frontier: np.ndarray = None,
|
| 128 |
+
) -> Image.Image:
|
| 129 |
+
"""Render full grid state as a top-down PIL Image.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
grid: 20×20 numpy array (0=empty, 1=hazard, 2=survivor)
|
| 133 |
+
agent_positions: {agent_id: (row, col)}
|
| 134 |
+
step: current simulation step
|
| 135 |
+
rescued: number of survivors rescued
|
| 136 |
+
priority_sectors: list of priority sector numbers
|
| 137 |
+
assignments: {agent_id: (target_row, target_col) or None}
|
| 138 |
+
scan_radius: current sensor radius
|
| 139 |
+
flood_frontier: boolean array marking flood edge cells
|
| 140 |
+
|
| 141 |
+
Returns:
|
| 142 |
+
PIL Image (640×640 RGB)
|
| 143 |
+
"""
|
| 144 |
+
if priority_sectors is None:
|
| 145 |
+
priority_sectors = []
|
| 146 |
+
if assignments is None:
|
| 147 |
+
assignments = {}
|
| 148 |
+
|
| 149 |
+
img = Image.new("RGB", (self.img_size, self.img_size), COLORS["background"])
|
| 150 |
+
draw = ImageDraw.Draw(img, "RGBA")
|
| 151 |
+
cs = self.cell_size
|
| 152 |
+
|
| 153 |
+
# --- Layer 1: Terrain cells ---
|
| 154 |
+
for r in range(GRID_SIZE):
|
| 155 |
+
for c in range(GRID_SIZE):
|
| 156 |
+
x0, y0 = c * cs, r * cs
|
| 157 |
+
x1, y1 = x0 + cs, y0 + cs
|
| 158 |
+
cell_val = grid[r, c]
|
| 159 |
+
|
| 160 |
+
if cell_val == HAZARD:
|
| 161 |
+
# Flood water — solid blue
|
| 162 |
+
draw.rectangle([x0, y0, x1, y1], fill=COLORS["hazard"])
|
| 163 |
+
elif cell_val == SURVIVOR:
|
| 164 |
+
# Survivor — red cell with glow
|
| 165 |
+
draw.rectangle([x0, y0, x1, y1], fill=COLORS["survivor"])
|
| 166 |
+
# Outer glow (slightly larger rectangle)
|
| 167 |
+
glow_pad = 2
|
| 168 |
+
draw.rectangle(
|
| 169 |
+
[x0 - glow_pad, y0 - glow_pad, x1 + glow_pad, y1 + glow_pad],
|
| 170 |
+
outline=COLORS["survivor"], width=1
|
| 171 |
+
)
|
| 172 |
+
else:
|
| 173 |
+
# Empty — dark navigable terrain
|
| 174 |
+
draw.rectangle([x0, y0, x1, y1], fill=COLORS["empty"])
|
| 175 |
+
|
| 176 |
+
# --- Layer 2: Flood frontier highlighting ---
|
| 177 |
+
if flood_frontier is not None:
|
| 178 |
+
for r in range(GRID_SIZE):
|
| 179 |
+
for c in range(GRID_SIZE):
|
| 180 |
+
if flood_frontier[r, c]:
|
| 181 |
+
x0, y0 = c * cs, r * cs
|
| 182 |
+
draw.rectangle(
|
| 183 |
+
[x0, y0, x0 + cs, y0 + cs],
|
| 184 |
+
outline=COLORS["flood_frontier"][:3], width=2
|
| 185 |
+
)
|
| 186 |
+
|
| 187 |
+
# --- Layer 3: Grid lines ---
|
| 188 |
+
for i in range(GRID_SIZE + 1):
|
| 189 |
+
pos = i * cs
|
| 190 |
+
draw.line([(pos, 0), (pos, self.img_size)], fill=COLORS["grid_line"], width=1)
|
| 191 |
+
draw.line([(0, pos), (self.img_size, pos)], fill=COLORS["grid_line"], width=1)
|
| 192 |
+
|
| 193 |
+
# --- Layer 4: Sector boundaries ---
|
| 194 |
+
for sec_num, (rs, re, cs_s, ce) in SECTOR_GRID.items():
|
| 195 |
+
x0, y0 = cs_s * cs, rs * cs
|
| 196 |
+
x1, y1 = ce * cs, re * cs
|
| 197 |
+
is_priority = sec_num in priority_sectors
|
| 198 |
+
color = COLORS["sector_priority"] if is_priority else COLORS["sector_line"]
|
| 199 |
+
width = 3 if is_priority else 1
|
| 200 |
+
|
| 201 |
+
draw.rectangle([x0, y0, x1, y1], outline=color, width=width)
|
| 202 |
+
|
| 203 |
+
# Priority sector fill overlay
|
| 204 |
+
if is_priority:
|
| 205 |
+
draw.rectangle(
|
| 206 |
+
[x0, y0, x1, y1],
|
| 207 |
+
fill=(0, 255, 255, 20)
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
# Sector number label
|
| 211 |
+
label_x = x0 + (ce - cs_s) * cs // 2
|
| 212 |
+
label_y = y0 + (re - rs) * cs // 2
|
| 213 |
+
draw.text(
|
| 214 |
+
(label_x, label_y), str(sec_num),
|
| 215 |
+
fill=color, font=self.font_small, anchor="mm"
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
# --- Layer 5: Assignment lines (robot → target) ---
|
| 219 |
+
for agent_id, target in assignments.items():
|
| 220 |
+
if target is not None and agent_id in agent_positions:
|
| 221 |
+
pos = agent_positions[agent_id]
|
| 222 |
+
# Draw dashed line from robot center to target center
|
| 223 |
+
ax, ay = pos[1] * cs + cs // 2, pos[0] * cs + cs // 2
|
| 224 |
+
tx, ty = target[1] * cs + cs // 2, target[0] * cs + cs // 2
|
| 225 |
+
self._draw_dashed_line(draw, (ax, ay), (tx, ty),
|
| 226 |
+
fill=COLORS["assignment_line"][:3], width=2, dash_len=6)
|
| 227 |
+
# Target star
|
| 228 |
+
draw.ellipse(
|
| 229 |
+
[tx - 4, ty - 4, tx + 4, ty + 4],
|
| 230 |
+
fill=COLORS["text_cyan"], outline=COLORS["text_white"]
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
# --- Layer 6: Scan radius circles ---
|
| 234 |
+
for agent_id, pos in agent_positions.items():
|
| 235 |
+
cx = pos[1] * cs + cs // 2
|
| 236 |
+
cy = pos[0] * cs + cs // 2
|
| 237 |
+
radius_px = scan_radius * cs
|
| 238 |
+
draw.ellipse(
|
| 239 |
+
[cx - radius_px, cy - radius_px, cx + radius_px, cy + radius_px],
|
| 240 |
+
outline=(0, 255, 255, 80), width=1
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
# --- Layer 7: Robot markers ---
|
| 244 |
+
for agent_id, pos in agent_positions.items():
|
| 245 |
+
cx = pos[1] * cs + cs // 2
|
| 246 |
+
cy = pos[0] * cs + cs // 2
|
| 247 |
+
robot_r = cs // 2 - 2
|
| 248 |
+
# Filled green circle with white border
|
| 249 |
+
draw.ellipse(
|
| 250 |
+
[cx - robot_r, cy - robot_r, cx + robot_r, cy + robot_r],
|
| 251 |
+
fill=COLORS["robot"], outline=COLORS["robot_border"], width=2
|
| 252 |
+
)
|
| 253 |
+
# Robot ID
|
| 254 |
+
draw.text(
|
| 255 |
+
(cx, cy), str(agent_id),
|
| 256 |
+
fill=COLORS["text_white"], font=self.font_medium, anchor="mm"
|
| 257 |
+
)
|
| 258 |
+
|
| 259 |
+
# --- Layer 8: HUD overlay ---
|
| 260 |
+
# Step counter (top-left)
|
| 261 |
+
draw.text(
|
| 262 |
+
(8, 6), f"Step: {step}",
|
| 263 |
+
fill=COLORS["text_white"], font=self.font_medium
|
| 264 |
+
)
|
| 265 |
+
# Rescued counter (top-right)
|
| 266 |
+
rescued_text = f"Rescued: {rescued}/5"
|
| 267 |
+
draw.text(
|
| 268 |
+
(self.img_size - 8, 6), rescued_text,
|
| 269 |
+
fill=COLORS["text_cyan"], font=self.font_medium, anchor="ra"
|
| 270 |
+
)
|
| 271 |
+
|
| 272 |
+
return img.convert("RGB")
|
| 273 |
+
|
| 274 |
+
def _draw_dashed_line(self, draw, start, end, fill, width=1, dash_len=8):
|
| 275 |
+
"""Draw a dashed line between two points."""
|
| 276 |
+
x0, y0 = start
|
| 277 |
+
x1, y1 = end
|
| 278 |
+
dx = x1 - x0
|
| 279 |
+
dy = y1 - y0
|
| 280 |
+
dist = math.sqrt(dx * dx + dy * dy)
|
| 281 |
+
if dist == 0:
|
| 282 |
+
return
|
| 283 |
+
dx_n, dy_n = dx / dist, dy / dist
|
| 284 |
+
pos = 0
|
| 285 |
+
drawing = True
|
| 286 |
+
while pos < dist:
|
| 287 |
+
seg_end = min(pos + dash_len, dist)
|
| 288 |
+
if drawing:
|
| 289 |
+
sx = int(x0 + dx_n * pos)
|
| 290 |
+
sy = int(y0 + dy_n * pos)
|
| 291 |
+
ex = int(x0 + dx_n * seg_end)
|
| 292 |
+
ey = int(y0 + dy_n * seg_end)
|
| 293 |
+
draw.line([(sx, sy), (ex, ey)], fill=fill, width=width)
|
| 294 |
+
pos = seg_end
|
| 295 |
+
drawing = not drawing
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
# ============================================================
|
| 299 |
+
# EGOCENTRIC PER-ROBOT FRAME RENDERER
|
| 300 |
+
# ============================================================
|
| 301 |
+
class EgocentricRenderer:
|
| 302 |
+
"""Renders what a single robot 'sees' from its position.
|
| 303 |
+
|
| 304 |
+
The egocentric frame is centered on the robot with a limited
|
| 305 |
+
field-of-view (FOV) determined by scan_radius. Cells outside
|
| 306 |
+
the FOV are rendered as fog (black). This is the key input for
|
| 307 |
+
Cosmos Reason 2's physical reasoning — the model must reason
|
| 308 |
+
about the physical world from a limited, noisy perspective.
|
| 309 |
+
|
| 310 |
+
Frame size: always 640×640 regardless of FOV, achieved by
|
| 311 |
+
scaling the visible region to fill the frame.
|
| 312 |
+
"""
|
| 313 |
+
|
| 314 |
+
def __init__(self, output_size: int = 640):
|
| 315 |
+
self.output_size = output_size
|
| 316 |
+
self._try_load_font()
|
| 317 |
+
|
| 318 |
+
def _try_load_font(self):
|
| 319 |
+
self.font_small = None
|
| 320 |
+
self.font_medium = None
|
| 321 |
+
try:
|
| 322 |
+
for path in [
|
| 323 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf",
|
| 324 |
+
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
| 325 |
+
]:
|
| 326 |
+
if os.path.exists(path):
|
| 327 |
+
self.font_small = ImageFont.truetype(path, 12)
|
| 328 |
+
self.font_medium = ImageFont.truetype(path, 16)
|
| 329 |
+
break
|
| 330 |
+
except Exception:
|
| 331 |
+
pass
|
| 332 |
+
if self.font_small is None:
|
| 333 |
+
self.font_small = ImageFont.load_default()
|
| 334 |
+
self.font_medium = ImageFont.load_default()
|
| 335 |
+
|
| 336 |
+
def render(
|
| 337 |
+
self,
|
| 338 |
+
grid: np.ndarray,
|
| 339 |
+
agent_id: int,
|
| 340 |
+
agent_positions: Dict[int, Tuple[int, int]],
|
| 341 |
+
belief_grid: np.ndarray = None,
|
| 342 |
+
scan_radius: int = 5,
|
| 343 |
+
use_belief: bool = False,
|
| 344 |
+
) -> Image.Image:
|
| 345 |
+
"""Render egocentric view for a single robot.
|
| 346 |
+
|
| 347 |
+
Args:
|
| 348 |
+
grid: 20×20 ground truth grid
|
| 349 |
+
agent_id: which robot's perspective
|
| 350 |
+
agent_positions: all robot positions
|
| 351 |
+
belief_grid: 20×20×3 Bayesian posterior (optional)
|
| 352 |
+
scan_radius: FOV radius in cells
|
| 353 |
+
use_belief: if True, render belief state instead of ground truth
|
| 354 |
+
|
| 355 |
+
Returns:
|
| 356 |
+
PIL Image (640×640 RGB) centered on the robot
|
| 357 |
+
"""
|
| 358 |
+
my_pos = agent_positions[agent_id]
|
| 359 |
+
my_r, my_c = my_pos
|
| 360 |
+
|
| 361 |
+
# Determine visible window: scan_radius cells in each direction
|
| 362 |
+
# We render a (2*scan_radius+1) × (2*scan_radius+1) region
|
| 363 |
+
view_size = 2 * scan_radius + 1
|
| 364 |
+
cell_px = self.output_size // view_size
|
| 365 |
+
|
| 366 |
+
img = Image.new("RGB", (self.output_size, self.output_size), COLORS["fog"])
|
| 367 |
+
draw = ImageDraw.Draw(img, "RGBA")
|
| 368 |
+
|
| 369 |
+
for dr in range(-scan_radius, scan_radius + 1):
|
| 370 |
+
for dc in range(-scan_radius, scan_radius + 1):
|
| 371 |
+
# Manhattan distance check for diamond-shaped FOV
|
| 372 |
+
if abs(dr) + abs(dc) > scan_radius:
|
| 373 |
+
continue
|
| 374 |
+
|
| 375 |
+
world_r = my_r + dr
|
| 376 |
+
world_c = my_c + dc
|
| 377 |
+
|
| 378 |
+
# Map to pixel coordinates in the egocentric frame
|
| 379 |
+
px_c = (dc + scan_radius) * cell_px
|
| 380 |
+
px_r = (dr + scan_radius) * cell_px
|
| 381 |
+
|
| 382 |
+
# Check bounds
|
| 383 |
+
if 0 <= world_r < GRID_SIZE and 0 <= world_c < GRID_SIZE:
|
| 384 |
+
if use_belief and belief_grid is not None:
|
| 385 |
+
# Render belief state — argmax of posterior
|
| 386 |
+
cell_val = belief_grid[world_r, world_c].argmax()
|
| 387 |
+
else:
|
| 388 |
+
cell_val = grid[world_r, world_c]
|
| 389 |
+
|
| 390 |
+
if cell_val == HAZARD:
|
| 391 |
+
fill = COLORS["hazard"]
|
| 392 |
+
elif cell_val == SURVIVOR:
|
| 393 |
+
fill = COLORS["survivor"]
|
| 394 |
+
else:
|
| 395 |
+
fill = COLORS["empty"]
|
| 396 |
+
else:
|
| 397 |
+
# Out of bounds — render as wall/boundary
|
| 398 |
+
fill = (80, 40, 20) # brown boundary
|
| 399 |
+
|
| 400 |
+
draw.rectangle(
|
| 401 |
+
[px_c, px_r, px_c + cell_px, px_r + cell_px],
|
| 402 |
+
fill=fill
|
| 403 |
+
)
|
| 404 |
+
|
| 405 |
+
# --- Grid lines ---
|
| 406 |
+
for i in range(view_size + 1):
|
| 407 |
+
pos = i * cell_px
|
| 408 |
+
draw.line([(pos, 0), (pos, self.output_size)], fill=COLORS["grid_line"], width=1)
|
| 409 |
+
draw.line([(0, pos), (self.output_size, pos)], fill=COLORS["grid_line"], width=1)
|
| 410 |
+
|
| 411 |
+
# --- Other robots visible in FOV ---
|
| 412 |
+
for other_id, other_pos in agent_positions.items():
|
| 413 |
+
dr = other_pos[0] - my_r
|
| 414 |
+
dc = other_pos[1] - my_c
|
| 415 |
+
if abs(dr) + abs(dc) <= scan_radius:
|
| 416 |
+
px_c = (dc + scan_radius) * cell_px + cell_px // 2
|
| 417 |
+
px_r = (dr + scan_radius) * cell_px + cell_px // 2
|
| 418 |
+
r_px = cell_px // 2 - 2
|
| 419 |
+
color = COLORS["robot"] if other_id != agent_id else (255, 255, 0) # yellow for self
|
| 420 |
+
draw.ellipse(
|
| 421 |
+
[px_c - r_px, px_r - r_px, px_c + r_px, px_r + r_px],
|
| 422 |
+
fill=color, outline=COLORS["robot_border"], width=2
|
| 423 |
+
)
|
| 424 |
+
draw.text(
|
| 425 |
+
(px_c, px_r), str(other_id),
|
| 426 |
+
fill=COLORS["text_white"], font=self.font_medium, anchor="mm"
|
| 427 |
+
)
|
| 428 |
+
|
| 429 |
+
# --- HUD: Robot ID and position ---
|
| 430 |
+
draw.text(
|
| 431 |
+
(8, 6), f"Robot {agent_id} | Pos: ({my_r},{my_c})",
|
| 432 |
+
fill=COLORS["text_cyan"], font=self.font_medium
|
| 433 |
+
)
|
| 434 |
+
draw.text(
|
| 435 |
+
(8, 26), f"FOV: r={scan_radius} | Sector: {get_sector_for_cell(my_r, my_c)}",
|
| 436 |
+
fill=COLORS["text_white"], font=self.font_small
|
| 437 |
+
)
|
| 438 |
+
|
| 439 |
+
return img.convert("RGB")
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
# ============================================================
|
| 443 |
+
# GROUND-TRUTH REASONING CHAIN GENERATOR
|
| 444 |
+
# ============================================================
|
| 445 |
+
class ReasoningChainGenerator:
|
| 446 |
+
"""Generates ground-truth physical reasoning chains for SFT training.
|
| 447 |
+
|
| 448 |
+
Given full simulation state (ground truth), produces structured
|
| 449 |
+
chain-of-thought reasoning that Cosmos Reason 2 should learn to
|
| 450 |
+
produce. Each chain has four components:
|
| 451 |
+
|
| 452 |
+
1. Spatial grounding — entity identification and coordinates
|
| 453 |
+
2. Temporal dynamics — flood prediction based on current state
|
| 454 |
+
3. Causal reasoning — which variables affect rescue outcomes
|
| 455 |
+
4. Decision reasoning — optimal robot-to-survivor allocation
|
| 456 |
+
"""
|
| 457 |
+
|
| 458 |
+
def generate(
|
| 459 |
+
self,
|
| 460 |
+
grid: np.ndarray,
|
| 461 |
+
agent_positions: Dict[int, Tuple[int, int]],
|
| 462 |
+
step: int,
|
| 463 |
+
rescued: int,
|
| 464 |
+
flood_velocity: Tuple[float, float] = None,
|
| 465 |
+
assignments: Dict[int, Optional[Tuple[int, int]]] = None,
|
| 466 |
+
scan_radius: int = 5,
|
| 467 |
+
) -> Dict:
|
| 468 |
+
"""Generate complete reasoning chain for a given state.
|
| 469 |
+
|
| 470 |
+
Returns dict with all four reasoning components plus metadata.
|
| 471 |
+
"""
|
| 472 |
+
survivors = self._find_entities(grid, SURVIVOR)
|
| 473 |
+
hazards = self._find_entities(grid, HAZARD)
|
| 474 |
+
flood_frontier = self._compute_flood_frontier(grid)
|
| 475 |
+
|
| 476 |
+
# --- Component 1: Spatial Grounding ---
|
| 477 |
+
spatial = self._spatial_grounding(
|
| 478 |
+
grid, agent_positions, survivors, hazards
|
| 479 |
+
)
|
| 480 |
+
|
| 481 |
+
# --- Component 2: Temporal Dynamics ---
|
| 482 |
+
temporal = self._temporal_dynamics(
|
| 483 |
+
grid, hazards, flood_frontier, step
|
| 484 |
+
)
|
| 485 |
+
|
| 486 |
+
# --- Component 3: Causal Reasoning ---
|
| 487 |
+
causal = self._causal_reasoning(
|
| 488 |
+
agent_positions, survivors, hazards, flood_frontier, scan_radius
|
| 489 |
+
)
|
| 490 |
+
|
| 491 |
+
# --- Component 4: Decision Reasoning ---
|
| 492 |
+
decision = self._decision_reasoning(
|
| 493 |
+
agent_positions, survivors, hazards, rescued
|
| 494 |
+
)
|
| 495 |
+
|
| 496 |
+
# --- Combined chain ---
|
| 497 |
+
chain = {
|
| 498 |
+
"step": step,
|
| 499 |
+
"rescued": rescued,
|
| 500 |
+
"num_survivors_remaining": len(survivors),
|
| 501 |
+
"num_hazard_cells": len(hazards),
|
| 502 |
+
"spatial_reasoning": spatial,
|
| 503 |
+
"temporal_reasoning": temporal,
|
| 504 |
+
"causal_reasoning": causal,
|
| 505 |
+
"decision_reasoning": decision,
|
| 506 |
+
"full_chain": self._format_full_chain(spatial, temporal, causal, decision, step, rescued),
|
| 507 |
+
}
|
| 508 |
+
|
| 509 |
+
return chain
|
| 510 |
+
|
| 511 |
+
def _find_entities(self, grid: np.ndarray, entity_type: int) -> List[Tuple[int, int]]:
|
| 512 |
+
coords = np.argwhere(grid == entity_type)
|
| 513 |
+
return [tuple(c) for c in coords]
|
| 514 |
+
|
| 515 |
+
def _compute_flood_frontier(self, grid: np.ndarray) -> List[Tuple[int, int]]:
|
| 516 |
+
"""Find flood cells adjacent to non-flood cells (expansion boundary)."""
|
| 517 |
+
frontier = []
|
| 518 |
+
for r in range(GRID_SIZE):
|
| 519 |
+
for c in range(GRID_SIZE):
|
| 520 |
+
if grid[r, c] == HAZARD:
|
| 521 |
+
for nr, nc in [(r-1,c), (r+1,c), (r,c-1), (r,c+1)]:
|
| 522 |
+
if 0 <= nr < GRID_SIZE and 0 <= nc < GRID_SIZE:
|
| 523 |
+
if grid[nr, nc] != HAZARD:
|
| 524 |
+
frontier.append((r, c))
|
| 525 |
+
break
|
| 526 |
+
return frontier
|
| 527 |
+
|
| 528 |
+
def _manhattan(self, a: Tuple[int, int], b: Tuple[int, int]) -> int:
|
| 529 |
+
return abs(a[0] - b[0]) + abs(a[1] - b[1])
|
| 530 |
+
|
| 531 |
+
def _spatial_grounding(
|
| 532 |
+
self, grid, agent_positions, survivors, hazards
|
| 533 |
+
) -> str:
|
| 534 |
+
lines = []
|
| 535 |
+
lines.append(f"Grid: {GRID_SIZE}×{GRID_SIZE}. {len(survivors)} survivors remaining. {len(hazards)} flood cells.")
|
| 536 |
+
|
| 537 |
+
for aid, pos in agent_positions.items():
|
| 538 |
+
sec = get_sector_for_cell(pos[0], pos[1])
|
| 539 |
+
lines.append(f"Robot {aid}: position ({pos[0]},{pos[1]}), sector {sec}.")
|
| 540 |
+
|
| 541 |
+
for i, s in enumerate(survivors):
|
| 542 |
+
sec = get_sector_for_cell(s[0], s[1])
|
| 543 |
+
nearest_robot = min(agent_positions.items(), key=lambda x: self._manhattan(x[1], s))
|
| 544 |
+
dist = self._manhattan(nearest_robot[1], s)
|
| 545 |
+
lines.append(
|
| 546 |
+
f"Survivor at ({s[0]},{s[1]}), sector {sec}. "
|
| 547 |
+
f"Nearest robot: {nearest_robot[0]} (distance {dist})."
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
return " ".join(lines)
|
| 551 |
+
|
| 552 |
+
def _temporal_dynamics(
|
| 553 |
+
self, grid, hazards, flood_frontier, step
|
| 554 |
+
) -> str:
|
| 555 |
+
lines = []
|
| 556 |
+
lines.append(f"Current step: {step}. Flood cells: {len(hazards)}. Frontier cells: {len(flood_frontier)}.")
|
| 557 |
+
|
| 558 |
+
if len(flood_frontier) > 0:
|
| 559 |
+
# Estimate flood expansion direction from frontier distribution
|
| 560 |
+
frontier_arr = np.array(flood_frontier)
|
| 561 |
+
center_r = frontier_arr[:, 0].mean()
|
| 562 |
+
center_c = frontier_arr[:, 1].mean()
|
| 563 |
+
hazard_arr = np.array(hazards) if hazards else frontier_arr
|
| 564 |
+
hazard_center_r = hazard_arr[:, 0].mean()
|
| 565 |
+
hazard_center_c = hazard_arr[:, 1].mean()
|
| 566 |
+
|
| 567 |
+
# Direction of expansion = frontier center - hazard center
|
| 568 |
+
dr = center_r - hazard_center_r
|
| 569 |
+
dc = center_c - hazard_center_c
|
| 570 |
+
|
| 571 |
+
direction = "stationary"
|
| 572 |
+
if abs(dr) > 0.5 or abs(dc) > 0.5:
|
| 573 |
+
dirs = []
|
| 574 |
+
if dr < -0.5: dirs.append("north")
|
| 575 |
+
if dr > 0.5: dirs.append("south")
|
| 576 |
+
if dc < -0.5: dirs.append("west")
|
| 577 |
+
if dc > 0.5: dirs.append("east")
|
| 578 |
+
direction = "-".join(dirs) if dirs else "outward"
|
| 579 |
+
|
| 580 |
+
lines.append(f"Flood expanding {direction}.")
|
| 581 |
+
|
| 582 |
+
# Predict flood at t+3, t+5, t+10 (simple linear extrapolation)
|
| 583 |
+
expansion_rate = len(flood_frontier) * 0.08 # ~8% per frontier cell per step
|
| 584 |
+
for dt in [3, 5, 10]:
|
| 585 |
+
predicted_cells = len(hazards) + int(expansion_rate * dt)
|
| 586 |
+
predicted_cells = min(predicted_cells, GRID_SIZE * GRID_SIZE)
|
| 587 |
+
lines.append(f"Predicted flood cells at step {step + dt}: ~{predicted_cells}.")
|
| 588 |
+
else:
|
| 589 |
+
lines.append("No active flood frontier detected.")
|
| 590 |
+
|
| 591 |
+
return " ".join(lines)
|
| 592 |
+
|
| 593 |
+
def _causal_reasoning(
|
| 594 |
+
self, agent_positions, survivors, hazards, flood_frontier, scan_radius
|
| 595 |
+
) -> str:
|
| 596 |
+
lines = []
|
| 597 |
+
|
| 598 |
+
# For each survivor, determine causal factors affecting rescue probability
|
| 599 |
+
for s in survivors:
|
| 600 |
+
sec = get_sector_for_cell(s[0], s[1])
|
| 601 |
+
# Factor 1: Distance to nearest robot
|
| 602 |
+
distances = {aid: self._manhattan(pos, s) for aid, pos in agent_positions.items()}
|
| 603 |
+
nearest_aid = min(distances, key=distances.get)
|
| 604 |
+
nearest_dist = distances[nearest_aid]
|
| 605 |
+
|
| 606 |
+
# Factor 2: Flood proximity
|
| 607 |
+
if flood_frontier:
|
| 608 |
+
flood_dists = [self._manhattan(s, f) for f in flood_frontier]
|
| 609 |
+
min_flood_dist = min(flood_dists)
|
| 610 |
+
else:
|
| 611 |
+
min_flood_dist = 99
|
| 612 |
+
|
| 613 |
+
# Factor 3: Urgency classification
|
| 614 |
+
if min_flood_dist <= 2:
|
| 615 |
+
urgency = "CRITICAL"
|
| 616 |
+
reason = f"flood frontier is {min_flood_dist} cells away"
|
| 617 |
+
elif min_flood_dist <= 5:
|
| 618 |
+
urgency = "HIGH"
|
| 619 |
+
reason = f"flood approaching ({min_flood_dist} cells)"
|
| 620 |
+
elif nearest_dist > 10:
|
| 621 |
+
urgency = "MEDIUM"
|
| 622 |
+
reason = f"far from nearest robot ({nearest_dist} cells)"
|
| 623 |
+
else:
|
| 624 |
+
urgency = "STANDARD"
|
| 625 |
+
reason = "accessible, no immediate threat"
|
| 626 |
+
|
| 627 |
+
lines.append(
|
| 628 |
+
f"Survivor ({s[0]},{s[1]}): urgency {urgency} — {reason}. "
|
| 629 |
+
f"Nearest robot: {nearest_aid} at distance {nearest_dist}."
|
| 630 |
+
)
|
| 631 |
+
|
| 632 |
+
# Causal dependencies
|
| 633 |
+
lines.append(
|
| 634 |
+
"Causal factors: rescue probability depends on (1) robot-survivor distance, "
|
| 635 |
+
"(2) flood proximity to survivor, (3) path traversability, "
|
| 636 |
+
"(4) competing allocation demands from other survivors."
|
| 637 |
+
)
|
| 638 |
+
|
| 639 |
+
return " ".join(lines)
|
| 640 |
+
|
| 641 |
+
def _decision_reasoning(
|
| 642 |
+
self, agent_positions, survivors, hazards, rescued
|
| 643 |
+
) -> str:
|
| 644 |
+
lines = []
|
| 645 |
+
|
| 646 |
+
if not survivors:
|
| 647 |
+
lines.append("No survivors remaining. Mission complete.")
|
| 648 |
+
return " ".join(lines)
|
| 649 |
+
|
| 650 |
+
# Compute optimal allocation via greedy nearest-first
|
| 651 |
+
# (matches MAELSTROM's FleetCoordinator logic)
|
| 652 |
+
pairs = []
|
| 653 |
+
for aid, pos in agent_positions.items():
|
| 654 |
+
for s in survivors:
|
| 655 |
+
dist = self._manhattan(pos, s)
|
| 656 |
+
pairs.append((dist, aid, s))
|
| 657 |
+
pairs.sort()
|
| 658 |
+
|
| 659 |
+
assigned_agents = set()
|
| 660 |
+
assigned_survivors = set()
|
| 661 |
+
allocation = {}
|
| 662 |
+
|
| 663 |
+
for dist, aid, s in pairs:
|
| 664 |
+
if aid in assigned_agents or s in assigned_survivors:
|
| 665 |
+
continue
|
| 666 |
+
allocation[aid] = s
|
| 667 |
+
assigned_agents.add(aid)
|
| 668 |
+
assigned_survivors.add(s)
|
| 669 |
+
|
| 670 |
+
for aid, target in allocation.items():
|
| 671 |
+
pos = agent_positions[aid]
|
| 672 |
+
dist = self._manhattan(pos, target)
|
| 673 |
+
sec = get_sector_for_cell(target[0], target[1])
|
| 674 |
+
lines.append(
|
| 675 |
+
f"Recommended: Robot {aid} ({pos[0]},{pos[1]}) → "
|
| 676 |
+
f"survivor ({target[0]},{target[1]}), sector {sec}, "
|
| 677 |
+
f"distance {dist} steps."
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
# Robots without assignment
|
| 681 |
+
for aid in agent_positions:
|
| 682 |
+
if aid not in allocation:
|
| 683 |
+
lines.append(f"Robot {aid}: no reachable unassigned survivor. Explore.")
|
| 684 |
+
|
| 685 |
+
remaining = len(survivors) - rescued
|
| 686 |
+
lines.append(f"Survivors remaining to rescue: {remaining}. Target: 5 total.")
|
| 687 |
+
|
| 688 |
+
return " ".join(lines)
|
| 689 |
+
|
| 690 |
+
def _format_full_chain(
|
| 691 |
+
self, spatial, temporal, causal, decision, step, rescued
|
| 692 |
+
) -> str:
|
| 693 |
+
"""Format all four components into a single reasoning chain."""
|
| 694 |
+
return (
|
| 695 |
+
f"[SPATIAL GROUNDING] {spatial}\n\n"
|
| 696 |
+
f"[TEMPORAL DYNAMICS] {temporal}\n\n"
|
| 697 |
+
f"[CAUSAL REASONING] {causal}\n\n"
|
| 698 |
+
f"[DECISION] {decision}"
|
| 699 |
+
)
|
| 700 |
+
|
| 701 |
+
|
| 702 |
+
# ============================================================
|
| 703 |
+
# DATASET GENERATOR — Produces (frame, chain) pairs from simulation
|
| 704 |
+
# ============================================================
|
| 705 |
+
class AEGISDatasetGenerator:
|
| 706 |
+
"""Runs MAELSTROM simulations and captures (frame, reasoning_chain)
|
| 707 |
+
pairs at each timestep for Cosmos Reason 2 SFT training data.
|
| 708 |
+
|
| 709 |
+
Usage:
|
| 710 |
+
gen = AEGISDatasetGenerator(output_dir="aegis_dataset")
|
| 711 |
+
gen.generate_from_simulation(
|
| 712 |
+
grid, agent_positions, commanders, step, rescued, ...
|
| 713 |
+
)
|
| 714 |
+
"""
|
| 715 |
+
|
| 716 |
+
def __init__(self, output_dir: str = "aegis_dataset"):
|
| 717 |
+
self.output_dir = output_dir
|
| 718 |
+
self.topdown = TopDownRenderer()
|
| 719 |
+
self.ego = EgocentricRenderer()
|
| 720 |
+
self.chain_gen = ReasoningChainGenerator()
|
| 721 |
+
self.sample_count = 0
|
| 722 |
+
|
| 723 |
+
# Create output directories
|
| 724 |
+
os.makedirs(f"{output_dir}/topdown", exist_ok=True)
|
| 725 |
+
os.makedirs(f"{output_dir}/egocentric", exist_ok=True)
|
| 726 |
+
os.makedirs(f"{output_dir}/chains", exist_ok=True)
|
| 727 |
+
os.makedirs(f"{output_dir}/pairs", exist_ok=True)
|
| 728 |
+
|
| 729 |
+
def capture_timestep(
|
| 730 |
+
self,
|
| 731 |
+
grid: np.ndarray,
|
| 732 |
+
agent_positions: Dict[int, Tuple[int, int]],
|
| 733 |
+
step: int,
|
| 734 |
+
rescued: int,
|
| 735 |
+
belief_grids: Dict[int, np.ndarray] = None,
|
| 736 |
+
priority_sectors: List[int] = None,
|
| 737 |
+
assignments: Dict[int, Optional[Tuple[int, int]]] = None,
|
| 738 |
+
scan_radius: int = 5,
|
| 739 |
+
scenario_id: str = "s0",
|
| 740 |
+
) -> Dict:
|
| 741 |
+
"""Capture one timestep: render frames + generate reasoning chain.
|
| 742 |
+
|
| 743 |
+
Returns:
|
| 744 |
+
Dict with file paths and metadata for this sample.
|
| 745 |
+
"""
|
| 746 |
+
sample_id = f"{scenario_id}_step{step:03d}"
|
| 747 |
+
|
| 748 |
+
# --- Compute flood frontier ---
|
| 749 |
+
flood_frontier = np.zeros((GRID_SIZE, GRID_SIZE), dtype=bool)
|
| 750 |
+
for r in range(GRID_SIZE):
|
| 751 |
+
for c in range(GRID_SIZE):
|
| 752 |
+
if grid[r, c] == HAZARD:
|
| 753 |
+
for nr, nc in [(r-1,c), (r+1,c), (r,c-1), (r,c+1)]:
|
| 754 |
+
if 0 <= nr < GRID_SIZE and 0 <= nc < GRID_SIZE:
|
| 755 |
+
if grid[nr, nc] != HAZARD:
|
| 756 |
+
flood_frontier[r, c] = True
|
| 757 |
+
break
|
| 758 |
+
|
| 759 |
+
# --- Top-down frame ---
|
| 760 |
+
topdown_img = self.topdown.render(
|
| 761 |
+
grid=grid,
|
| 762 |
+
agent_positions=agent_positions,
|
| 763 |
+
step=step,
|
| 764 |
+
rescued=rescued,
|
| 765 |
+
priority_sectors=priority_sectors or [],
|
| 766 |
+
assignments=assignments or {},
|
| 767 |
+
scan_radius=scan_radius,
|
| 768 |
+
flood_frontier=flood_frontier,
|
| 769 |
+
)
|
| 770 |
+
topdown_path = f"{self.output_dir}/topdown/{sample_id}_topdown.png"
|
| 771 |
+
topdown_img.save(topdown_path)
|
| 772 |
+
|
| 773 |
+
# --- Egocentric frames (one per robot) ---
|
| 774 |
+
ego_paths = {}
|
| 775 |
+
for agent_id in agent_positions:
|
| 776 |
+
belief = belief_grids.get(agent_id) if belief_grids else None
|
| 777 |
+
ego_img = self.ego.render(
|
| 778 |
+
grid=grid,
|
| 779 |
+
agent_id=agent_id,
|
| 780 |
+
agent_positions=agent_positions,
|
| 781 |
+
belief_grid=belief,
|
| 782 |
+
scan_radius=scan_radius,
|
| 783 |
+
use_belief=False, # Ground truth for training data
|
| 784 |
+
)
|
| 785 |
+
ego_path = f"{self.output_dir}/egocentric/{sample_id}_robot{agent_id}.png"
|
| 786 |
+
ego_img.save(ego_path)
|
| 787 |
+
ego_paths[agent_id] = ego_path
|
| 788 |
+
|
| 789 |
+
# --- Reasoning chain ---
|
| 790 |
+
chain = self.chain_gen.generate(
|
| 791 |
+
grid=grid,
|
| 792 |
+
agent_positions=agent_positions,
|
| 793 |
+
step=step,
|
| 794 |
+
rescued=rescued,
|
| 795 |
+
assignments=assignments,
|
| 796 |
+
scan_radius=scan_radius,
|
| 797 |
+
)
|
| 798 |
+
chain_path = f"{self.output_dir}/chains/{sample_id}_chain.json"
|
| 799 |
+
with open(chain_path, "w") as f:
|
| 800 |
+
json.dump(chain, f, indent=2)
|
| 801 |
+
|
| 802 |
+
# --- Combined pair record ---
|
| 803 |
+
pair = {
|
| 804 |
+
"sample_id": sample_id,
|
| 805 |
+
"scenario_id": scenario_id,
|
| 806 |
+
"step": step,
|
| 807 |
+
"rescued": rescued,
|
| 808 |
+
"topdown_frame": topdown_path,
|
| 809 |
+
"egocentric_frames": ego_paths,
|
| 810 |
+
"reasoning_chain": chain["full_chain"],
|
| 811 |
+
"chain_components": {
|
| 812 |
+
"spatial": chain["spatial_reasoning"],
|
| 813 |
+
"temporal": chain["temporal_reasoning"],
|
| 814 |
+
"causal": chain["causal_reasoning"],
|
| 815 |
+
"decision": chain["decision_reasoning"],
|
| 816 |
+
},
|
| 817 |
+
"metadata": {
|
| 818 |
+
"num_survivors": chain["num_survivors_remaining"],
|
| 819 |
+
"num_hazards": chain["num_hazard_cells"],
|
| 820 |
+
"scan_radius": scan_radius,
|
| 821 |
+
}
|
| 822 |
+
}
|
| 823 |
+
pair_path = f"{self.output_dir}/pairs/{sample_id}.json"
|
| 824 |
+
with open(pair_path, "w") as f:
|
| 825 |
+
json.dump(pair, f, indent=2)
|
| 826 |
+
|
| 827 |
+
self.sample_count += 1
|
| 828 |
+
return pair
|
| 829 |
+
|
| 830 |
+
|
| 831 |
+
# ============================================================
|
| 832 |
+
# QUICK TEST — Renders a sample frame from a random grid state
|
| 833 |
+
# ============================================================
|
| 834 |
+
def quick_test(output_dir: str = "aegis_test"):
|
| 835 |
+
"""Generate sample frames from a random MAELSTROM-like state."""
|
| 836 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 837 |
+
|
| 838 |
+
np.random.seed(42)
|
| 839 |
+
|
| 840 |
+
# Create a sample grid
|
| 841 |
+
grid = np.zeros((GRID_SIZE, GRID_SIZE), dtype=int)
|
| 842 |
+
|
| 843 |
+
# Place hazards (flood)
|
| 844 |
+
for _ in range(15):
|
| 845 |
+
r, c = np.random.randint(0, GRID_SIZE, 2)
|
| 846 |
+
grid[r, c] = HAZARD
|
| 847 |
+
# Expand flood to make it contiguous
|
| 848 |
+
for _ in range(3):
|
| 849 |
+
new_grid = grid.copy()
|
| 850 |
+
for r in range(GRID_SIZE):
|
| 851 |
+
for c in range(GRID_SIZE):
|
| 852 |
+
if grid[r, c] == HAZARD:
|
| 853 |
+
for nr, nc in [(r-1,c), (r+1,c), (r,c-1), (r,c+1)]:
|
| 854 |
+
if 0 <= nr < GRID_SIZE and 0 <= nc < GRID_SIZE:
|
| 855 |
+
if grid[nr, nc] == EMPTY and np.random.random() < 0.3:
|
| 856 |
+
new_grid[nr, nc] = HAZARD
|
| 857 |
+
grid = new_grid
|
| 858 |
+
|
| 859 |
+
# Place survivors
|
| 860 |
+
survivors_placed = 0
|
| 861 |
+
while survivors_placed < 5:
|
| 862 |
+
r, c = np.random.randint(0, GRID_SIZE, 2)
|
| 863 |
+
if grid[r, c] == EMPTY:
|
| 864 |
+
grid[r, c] = SURVIVOR
|
| 865 |
+
survivors_placed += 1
|
| 866 |
+
|
| 867 |
+
# Place agents
|
| 868 |
+
agent_positions = {}
|
| 869 |
+
for i in range(3):
|
| 870 |
+
while True:
|
| 871 |
+
r, c = np.random.randint(0, GRID_SIZE, 2)
|
| 872 |
+
if grid[r, c] == EMPTY:
|
| 873 |
+
agent_positions[i] = (r, c)
|
| 874 |
+
break
|
| 875 |
+
|
| 876 |
+
# Assignments (nearest survivor per robot)
|
| 877 |
+
survivors = list(zip(*np.where(grid == SURVIVOR)))
|
| 878 |
+
assignments = {}
|
| 879 |
+
used = set()
|
| 880 |
+
for aid, pos in agent_positions.items():
|
| 881 |
+
best = None
|
| 882 |
+
best_d = 999
|
| 883 |
+
for s in survivors:
|
| 884 |
+
if s not in used:
|
| 885 |
+
d = abs(pos[0]-s[0]) + abs(pos[1]-s[1])
|
| 886 |
+
if d < best_d:
|
| 887 |
+
best_d = d
|
| 888 |
+
best = s
|
| 889 |
+
if best:
|
| 890 |
+
assignments[aid] = best
|
| 891 |
+
used.add(best)
|
| 892 |
+
|
| 893 |
+
# --- Render top-down ---
|
| 894 |
+
renderer = TopDownRenderer()
|
| 895 |
+
img = renderer.render(
|
| 896 |
+
grid=grid,
|
| 897 |
+
agent_positions=agent_positions,
|
| 898 |
+
step=12,
|
| 899 |
+
rescued=2,
|
| 900 |
+
priority_sectors=[4, 7],
|
| 901 |
+
assignments=assignments,
|
| 902 |
+
scan_radius=5,
|
| 903 |
+
)
|
| 904 |
+
topdown_path = f"{output_dir}/sample_topdown.png"
|
| 905 |
+
img.save(topdown_path)
|
| 906 |
+
print(f"Top-down frame saved: {topdown_path} ({img.size[0]}×{img.size[1]})")
|
| 907 |
+
|
| 908 |
+
# --- Render egocentric for each robot ---
|
| 909 |
+
ego_renderer = EgocentricRenderer()
|
| 910 |
+
for aid in agent_positions:
|
| 911 |
+
ego_img = ego_renderer.render(
|
| 912 |
+
grid=grid,
|
| 913 |
+
agent_id=aid,
|
| 914 |
+
agent_positions=agent_positions,
|
| 915 |
+
scan_radius=5,
|
| 916 |
+
)
|
| 917 |
+
ego_path = f"{output_dir}/sample_ego_robot{aid}.png"
|
| 918 |
+
ego_img.save(ego_path)
|
| 919 |
+
print(f"Egocentric frame (Robot {aid}) saved: {ego_path} ({ego_img.size[0]}×{ego_img.size[1]})")
|
| 920 |
+
|
| 921 |
+
# --- Generate reasoning chain ---
|
| 922 |
+
chain_gen = ReasoningChainGenerator()
|
| 923 |
+
chain = chain_gen.generate(
|
| 924 |
+
grid=grid,
|
| 925 |
+
agent_positions=agent_positions,
|
| 926 |
+
step=12,
|
| 927 |
+
rescued=2,
|
| 928 |
+
assignments=assignments,
|
| 929 |
+
scan_radius=5,
|
| 930 |
+
)
|
| 931 |
+
chain_path = f"{output_dir}/sample_chain.json"
|
| 932 |
+
with open(chain_path, "w") as f:
|
| 933 |
+
json.dump(chain, f, indent=2)
|
| 934 |
+
print(f"Reasoning chain saved: {chain_path}")
|
| 935 |
+
|
| 936 |
+
# Print the full chain
|
| 937 |
+
print("\n" + "=" * 70)
|
| 938 |
+
print("SAMPLE REASONING CHAIN:")
|
| 939 |
+
print("=" * 70)
|
| 940 |
+
print(chain["full_chain"])
|
| 941 |
+
|
| 942 |
+
return topdown_path, chain
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
if __name__ == "__main__":
|
| 946 |
+
quick_test()
|
aegis-reason/aegis-reason/aegis_varp.py
ADDED
|
@@ -0,0 +1,536 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
VARP — Visual-Action Reasoning Precision Framework
|
| 3 |
+
====================================================
|
| 4 |
+
Evaluates AEGIS-Reason model outputs against ground truth reasoning
|
| 5 |
+
chains from the MAELSTROM simulation oracle.
|
| 6 |
+
|
| 7 |
+
Four evaluation axes (matching the 4-component reasoning chain):
|
| 8 |
+
1. SPATIAL — Entity identification + localization accuracy
|
| 9 |
+
2. TEMPORAL — Flood prediction accuracy
|
| 10 |
+
3. CAUSAL — Urgency classification correctness
|
| 11 |
+
4. DECISION — Assignment optimality vs oracle
|
| 12 |
+
|
| 13 |
+
Usage:
|
| 14 |
+
# Evaluate a batch of model outputs against ground truth
|
| 15 |
+
python aegis_varp.py \
|
| 16 |
+
--predictions inference_results.json \
|
| 17 |
+
--ground-truth aegis_dataset/chains/ \
|
| 18 |
+
--output varp_report.json
|
| 19 |
+
|
| 20 |
+
# Quick eval on a single sample
|
| 21 |
+
python aegis_varp.py \
|
| 22 |
+
--pred-text "model output text" \
|
| 23 |
+
--gt-chain aegis_dataset/chains/seed001_b2.0_no_intel_step006.json
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
import json
|
| 27 |
+
import os
|
| 28 |
+
import re
|
| 29 |
+
import argparse
|
| 30 |
+
import numpy as np
|
| 31 |
+
from typing import Dict, List, Tuple, Optional
|
| 32 |
+
from pathlib import Path
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# ============================================================
|
| 36 |
+
# SPATIAL GROUNDING EVALUATOR
|
| 37 |
+
# ============================================================
|
| 38 |
+
class SpatialEvaluator:
|
| 39 |
+
"""Measures entity identification and localization accuracy."""
|
| 40 |
+
|
| 41 |
+
def evaluate(self, prediction: str, ground_truth: Dict) -> Dict:
|
| 42 |
+
"""Compare predicted spatial grounding against oracle.
|
| 43 |
+
|
| 44 |
+
Metrics:
|
| 45 |
+
- entity_recall: fraction of GT entities mentioned in prediction
|
| 46 |
+
- position_accuracy: fraction of mentioned entities with correct positions
|
| 47 |
+
- count_accuracy: whether entity counts are correct
|
| 48 |
+
"""
|
| 49 |
+
gt_text = ground_truth.get("spatial_reasoning", "")
|
| 50 |
+
gt_total_survivors = ground_truth.get("num_survivors_remaining", 0)
|
| 51 |
+
gt_total_hazards = ground_truth.get("num_hazard_cells", 0)
|
| 52 |
+
|
| 53 |
+
# Parse robots from GT text: "Robot 0: position (2,6), sector 2"
|
| 54 |
+
gt_robots = []
|
| 55 |
+
for m in re.finditer(r'Robot (\d+): position \((\d+),(\d+)\)', gt_text):
|
| 56 |
+
gt_robots.append({"id": int(m.group(1)), "position": [int(m.group(2)), int(m.group(3))]})
|
| 57 |
+
|
| 58 |
+
# Parse survivors from GT text: "Survivor at (6,10)"
|
| 59 |
+
gt_survivors = []
|
| 60 |
+
for m in re.finditer(r'Survivor at \((\d+),(\d+)\)', gt_text):
|
| 61 |
+
gt_survivors.append({"position": [int(m.group(1)), int(m.group(2))]})
|
| 62 |
+
|
| 63 |
+
# Parse prediction for entity mentions
|
| 64 |
+
pred_lower = prediction.lower()
|
| 65 |
+
|
| 66 |
+
# Count robot mentions
|
| 67 |
+
robots_found = 0
|
| 68 |
+
robots_correct_pos = 0
|
| 69 |
+
for robot in gt_robots:
|
| 70 |
+
robot_id = robot.get("id", -1)
|
| 71 |
+
pos = robot.get("position", [])
|
| 72 |
+
# Check if robot is mentioned
|
| 73 |
+
if f"robot {robot_id}" in pred_lower or f"robot{robot_id}" in pred_lower:
|
| 74 |
+
robots_found += 1
|
| 75 |
+
# Check position accuracy
|
| 76 |
+
if pos and f"({pos[0]},{pos[1]})" in prediction.replace(" ", ""):
|
| 77 |
+
robots_correct_pos += 1
|
| 78 |
+
elif pos and f"({pos[0]}, {pos[1]})" in prediction:
|
| 79 |
+
robots_correct_pos += 1
|
| 80 |
+
|
| 81 |
+
# Count survivor mentions (by position)
|
| 82 |
+
survivors_found = 0
|
| 83 |
+
survivors_correct_pos = 0
|
| 84 |
+
for surv in gt_survivors:
|
| 85 |
+
pos = surv.get("position", [])
|
| 86 |
+
if pos:
|
| 87 |
+
pos_str1 = f"({pos[0]},{pos[1]})"
|
| 88 |
+
pos_str2 = f"({pos[0]}, {pos[1]})"
|
| 89 |
+
if pos_str1 in prediction.replace(" ", "") or pos_str2 in prediction:
|
| 90 |
+
survivors_found += 1
|
| 91 |
+
survivors_correct_pos += 1
|
| 92 |
+
|
| 93 |
+
# Check counts
|
| 94 |
+
count_correct = 0
|
| 95 |
+
count_total = 2 # survivors + hazards
|
| 96 |
+
|
| 97 |
+
# Check survivor count
|
| 98 |
+
surv_patterns = [
|
| 99 |
+
f"{gt_total_survivors} survivor",
|
| 100 |
+
f"{gt_total_survivors} remaining",
|
| 101 |
+
]
|
| 102 |
+
if any(p in pred_lower for p in surv_patterns):
|
| 103 |
+
count_correct += 1
|
| 104 |
+
|
| 105 |
+
# Check hazard count
|
| 106 |
+
hazard_patterns = [
|
| 107 |
+
f"{gt_total_hazards} flood",
|
| 108 |
+
f"{gt_total_hazards} hazard",
|
| 109 |
+
]
|
| 110 |
+
if any(p in pred_lower for p in hazard_patterns):
|
| 111 |
+
count_correct += 1
|
| 112 |
+
|
| 113 |
+
total_entities = len(gt_robots) + len(gt_survivors)
|
| 114 |
+
entities_found = robots_found + survivors_found
|
| 115 |
+
entities_positioned = robots_correct_pos + survivors_correct_pos
|
| 116 |
+
|
| 117 |
+
return {
|
| 118 |
+
"entity_recall": entities_found / max(total_entities, 1),
|
| 119 |
+
"position_accuracy": entities_positioned / max(entities_found, 1),
|
| 120 |
+
"count_accuracy": count_correct / max(count_total, 1),
|
| 121 |
+
"robots_found": robots_found,
|
| 122 |
+
"robots_total": len(gt_robots),
|
| 123 |
+
"survivors_found": survivors_found,
|
| 124 |
+
"survivors_total": len(gt_survivors),
|
| 125 |
+
"score": (
|
| 126 |
+
0.4 * (entities_found / max(total_entities, 1)) +
|
| 127 |
+
0.4 * (entities_positioned / max(entities_found, 1)) +
|
| 128 |
+
0.2 * (count_correct / max(count_total, 1))
|
| 129 |
+
),
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
# ============================================================
|
| 134 |
+
# TEMPORAL DYNAMICS EVALUATOR
|
| 135 |
+
# ============================================================
|
| 136 |
+
class TemporalEvaluator:
|
| 137 |
+
"""Measures flood prediction accuracy."""
|
| 138 |
+
|
| 139 |
+
def evaluate(self, prediction: str, ground_truth: Dict) -> Dict:
|
| 140 |
+
"""Compare predicted temporal dynamics against oracle.
|
| 141 |
+
|
| 142 |
+
Metrics:
|
| 143 |
+
- flood_count_error: absolute error in current flood cell count
|
| 144 |
+
- trend_correct: whether expansion direction is correct
|
| 145 |
+
- prediction_accuracy: how close predicted future floods are
|
| 146 |
+
"""
|
| 147 |
+
gt_text = ground_truth.get("temporal_reasoning", "")
|
| 148 |
+
|
| 149 |
+
# Parse flood cells from GT text: "Flood cells: 18"
|
| 150 |
+
gt_flood_match = re.search(r'Flood cells: (\d+)', gt_text)
|
| 151 |
+
gt_flood_cells = int(gt_flood_match.group(1)) if gt_flood_match else ground_truth.get("num_hazard_cells", 0)
|
| 152 |
+
|
| 153 |
+
gt_frontier_match = re.search(r'Frontier cells: (\d+)', gt_text)
|
| 154 |
+
gt_frontier = int(gt_frontier_match.group(1)) if gt_frontier_match else 0
|
| 155 |
+
|
| 156 |
+
# Parse predictions from GT text: "Predicted flood cells at step 9: ~22"
|
| 157 |
+
gt_predictions = {}
|
| 158 |
+
for m in re.finditer(r'Predicted flood cells at step (\d+): ~(\d+)', gt_text):
|
| 159 |
+
gt_predictions[int(m.group(1))] = int(m.group(2))
|
| 160 |
+
|
| 161 |
+
# Parse current flood count from prediction
|
| 162 |
+
pred_flood = self._extract_number(prediction, r"(\d+)\s*flood\s*cell")
|
| 163 |
+
if pred_flood is None:
|
| 164 |
+
pred_flood = self._extract_number(prediction, r"flood\s*cells?:\s*(\d+)")
|
| 165 |
+
if pred_flood is None:
|
| 166 |
+
pred_flood = self._extract_number(prediction, r"(\d+)\s*hazard")
|
| 167 |
+
|
| 168 |
+
flood_error = abs(pred_flood - gt_flood_cells) if pred_flood is not None else gt_flood_cells
|
| 169 |
+
|
| 170 |
+
# Check if prediction mentions expansion
|
| 171 |
+
pred_lower = prediction.lower()
|
| 172 |
+
mentions_expansion = any(w in pred_lower for w in ["expand", "spread", "growing", "frontier", "advancing"])
|
| 173 |
+
|
| 174 |
+
# Check predicted future values
|
| 175 |
+
prediction_errors = []
|
| 176 |
+
for gt_step, gt_val in gt_predictions.items():
|
| 177 |
+
# Try to find predicted value for this timestep in model output
|
| 178 |
+
step_pattern = rf'step\s*{gt_step}.*?(\d+)'
|
| 179 |
+
step_match = re.search(step_pattern, prediction, re.IGNORECASE)
|
| 180 |
+
if step_match:
|
| 181 |
+
pred_val = int(step_match.group(1))
|
| 182 |
+
prediction_errors.append(abs(pred_val - gt_val) / max(gt_val, 1))
|
| 183 |
+
|
| 184 |
+
avg_pred_error = np.mean(prediction_errors) if prediction_errors else 1.0
|
| 185 |
+
|
| 186 |
+
# Compute score
|
| 187 |
+
flood_score = max(0, 1.0 - flood_error / max(gt_flood_cells, 1))
|
| 188 |
+
trend_score = 1.0 if mentions_expansion and gt_frontier > 0 else 0.0
|
| 189 |
+
pred_score = max(0, 1.0 - avg_pred_error)
|
| 190 |
+
|
| 191 |
+
return {
|
| 192 |
+
"flood_count_error": flood_error,
|
| 193 |
+
"gt_flood_cells": gt_flood_cells,
|
| 194 |
+
"pred_flood_cells": pred_flood,
|
| 195 |
+
"trend_correct": mentions_expansion,
|
| 196 |
+
"prediction_accuracy": pred_score,
|
| 197 |
+
"score": 0.4 * flood_score + 0.3 * trend_score + 0.3 * pred_score,
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
@staticmethod
|
| 201 |
+
def _extract_number(text: str, pattern: str) -> Optional[int]:
|
| 202 |
+
match = re.search(pattern, text, re.IGNORECASE)
|
| 203 |
+
return int(match.group(1)) if match else None
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
# ============================================================
|
| 207 |
+
# CAUSAL REASONING EVALUATOR
|
| 208 |
+
# ============================================================
|
| 209 |
+
class CausalEvaluator:
|
| 210 |
+
"""Measures urgency classification correctness."""
|
| 211 |
+
|
| 212 |
+
def evaluate(self, prediction: str, ground_truth: Dict) -> Dict:
|
| 213 |
+
"""Compare predicted urgency assessments against oracle.
|
| 214 |
+
|
| 215 |
+
Metrics:
|
| 216 |
+
- urgency_accuracy: fraction of survivors with correct urgency level
|
| 217 |
+
- critical_recall: fraction of CRITICAL survivors correctly identified
|
| 218 |
+
"""
|
| 219 |
+
gt_text = ground_truth.get("causal_reasoning", "")
|
| 220 |
+
|
| 221 |
+
# Parse assessments from GT text: "Survivor (6,10): urgency STANDARD"
|
| 222 |
+
gt_assessments = []
|
| 223 |
+
for m in re.finditer(r'Survivor \((\d+),(\d+)\): urgency (\w+)', gt_text):
|
| 224 |
+
gt_assessments.append({
|
| 225 |
+
"position": [int(m.group(1)), int(m.group(2))],
|
| 226 |
+
"urgency": m.group(3),
|
| 227 |
+
})
|
| 228 |
+
|
| 229 |
+
if not gt_assessments:
|
| 230 |
+
return {"urgency_accuracy": 1.0, "critical_recall": 1.0, "score": 1.0}
|
| 231 |
+
|
| 232 |
+
pred_lower = prediction.lower()
|
| 233 |
+
|
| 234 |
+
# Try to isolate the causal section of the prediction
|
| 235 |
+
causal_section = prediction
|
| 236 |
+
causal_start = prediction.upper().find("[CAUSAL")
|
| 237 |
+
if causal_start >= 0:
|
| 238 |
+
causal_end = prediction.upper().find("[DECISION", causal_start)
|
| 239 |
+
if causal_end > 0:
|
| 240 |
+
causal_section = prediction[causal_start:causal_end]
|
| 241 |
+
else:
|
| 242 |
+
causal_section = prediction[causal_start:]
|
| 243 |
+
|
| 244 |
+
correct = 0
|
| 245 |
+
critical_total = 0
|
| 246 |
+
critical_found = 0
|
| 247 |
+
|
| 248 |
+
for assessment in gt_assessments:
|
| 249 |
+
pos = assessment.get("position", [])
|
| 250 |
+
gt_urgency = assessment.get("urgency", "STANDARD")
|
| 251 |
+
|
| 252 |
+
if gt_urgency == "CRITICAL":
|
| 253 |
+
critical_total += 1
|
| 254 |
+
|
| 255 |
+
if not pos:
|
| 256 |
+
continue
|
| 257 |
+
|
| 258 |
+
# Search for this survivor's urgency in the causal section
|
| 259 |
+
pos_pattern = rf'\({pos[0]}\s*,\s*{pos[1]}\)'
|
| 260 |
+
|
| 261 |
+
pos_match = re.search(pos_pattern, causal_section)
|
| 262 |
+
if pos_match:
|
| 263 |
+
context = causal_section[pos_match.start():pos_match.start()+300].upper()
|
| 264 |
+
|
| 265 |
+
pred_urgency = None
|
| 266 |
+
for level in ["CRITICAL", "HIGH", "MEDIUM", "STANDARD"]:
|
| 267 |
+
if level in context:
|
| 268 |
+
pred_urgency = level
|
| 269 |
+
break
|
| 270 |
+
|
| 271 |
+
if pred_urgency == gt_urgency:
|
| 272 |
+
correct += 1
|
| 273 |
+
if gt_urgency == "CRITICAL":
|
| 274 |
+
critical_found += 1
|
| 275 |
+
|
| 276 |
+
urgency_acc = correct / max(len(gt_assessments), 1)
|
| 277 |
+
critical_rec = critical_found / max(critical_total, 1)
|
| 278 |
+
|
| 279 |
+
return {
|
| 280 |
+
"urgency_accuracy": urgency_acc,
|
| 281 |
+
"critical_recall": critical_rec,
|
| 282 |
+
"correct": correct,
|
| 283 |
+
"total_assessed": len(gt_assessments),
|
| 284 |
+
"critical_found": critical_found,
|
| 285 |
+
"critical_total": critical_total,
|
| 286 |
+
"score": 0.6 * urgency_acc + 0.4 * critical_rec,
|
| 287 |
+
}
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
# ============================================================
|
| 291 |
+
# DECISION EVALUATOR
|
| 292 |
+
# ============================================================
|
| 293 |
+
class DecisionEvaluator:
|
| 294 |
+
"""Measures assignment optimality vs oracle."""
|
| 295 |
+
|
| 296 |
+
def evaluate(self, prediction: str, ground_truth: Dict) -> Dict:
|
| 297 |
+
"""Compare predicted robot assignments against oracle optimal.
|
| 298 |
+
|
| 299 |
+
Metrics:
|
| 300 |
+
- assignment_match: fraction of assignments matching oracle
|
| 301 |
+
- distance_efficiency: ratio of oracle distance to predicted distance
|
| 302 |
+
"""
|
| 303 |
+
gt_text = ground_truth.get("decision_reasoning", "")
|
| 304 |
+
|
| 305 |
+
# Parse assignments from GT text: "Robot 2 (17,7) → survivor (19,7), sector 14, distance 2 steps"
|
| 306 |
+
gt_assignments = []
|
| 307 |
+
for m in re.finditer(r'Robot (\d+) \((\d+),(\d+)\) .* survivor \((\d+),(\d+)\).* distance (\d+)', gt_text):
|
| 308 |
+
gt_assignments.append({
|
| 309 |
+
"robot_id": int(m.group(1)),
|
| 310 |
+
"robot_pos": [int(m.group(2)), int(m.group(3))],
|
| 311 |
+
"target": [int(m.group(4)), int(m.group(5))],
|
| 312 |
+
"distance": int(m.group(6)),
|
| 313 |
+
})
|
| 314 |
+
|
| 315 |
+
if not gt_assignments:
|
| 316 |
+
return {"assignment_match": 1.0, "distance_efficiency": 1.0, "score": 1.0}
|
| 317 |
+
|
| 318 |
+
# Isolate decision section
|
| 319 |
+
decision_section = prediction
|
| 320 |
+
dec_start = prediction.upper().find("[DECISION")
|
| 321 |
+
if dec_start >= 0:
|
| 322 |
+
decision_section = prediction[dec_start:]
|
| 323 |
+
|
| 324 |
+
matches = 0
|
| 325 |
+
total_gt_dist = 0
|
| 326 |
+
total_pred_dist = 0
|
| 327 |
+
|
| 328 |
+
for assign in gt_assignments:
|
| 329 |
+
robot_id = assign.get("robot_id", -1)
|
| 330 |
+
target = assign.get("target", [])
|
| 331 |
+
gt_dist = assign.get("distance", 0)
|
| 332 |
+
total_gt_dist += gt_dist
|
| 333 |
+
|
| 334 |
+
if not target:
|
| 335 |
+
continue
|
| 336 |
+
|
| 337 |
+
# Check if prediction matches this assignment
|
| 338 |
+
# Look for "Robot X ... survivor (r,c)" patterns in decision section
|
| 339 |
+
target_str = f"({target[0]},{target[1]})"
|
| 340 |
+
target_str2 = f"({target[0]}, {target[1]})"
|
| 341 |
+
robot_pattern = rf'Robot\s*{robot_id}'
|
| 342 |
+
|
| 343 |
+
found_match = False
|
| 344 |
+
# Find robot mention in decision section
|
| 345 |
+
for rmatch in re.finditer(robot_pattern, decision_section, re.IGNORECASE):
|
| 346 |
+
context = decision_section[rmatch.start():rmatch.start()+200]
|
| 347 |
+
if target_str.replace(" ", "") in context.replace(" ", "") or target_str2 in context:
|
| 348 |
+
found_match = True
|
| 349 |
+
matches += 1
|
| 350 |
+
total_pred_dist += gt_dist
|
| 351 |
+
break
|
| 352 |
+
|
| 353 |
+
if not found_match:
|
| 354 |
+
total_pred_dist += gt_dist * 1.5 # Penalty for missed assignment
|
| 355 |
+
|
| 356 |
+
assignment_match = matches / max(len(gt_assignments), 1)
|
| 357 |
+
distance_eff = total_gt_dist / max(total_pred_dist, 1)
|
| 358 |
+
distance_eff = min(distance_eff, 1.0) # Cap at 1.0
|
| 359 |
+
|
| 360 |
+
return {
|
| 361 |
+
"assignment_match": assignment_match,
|
| 362 |
+
"distance_efficiency": distance_eff,
|
| 363 |
+
"matches": matches,
|
| 364 |
+
"total_assignments": len(gt_assignments),
|
| 365 |
+
"score": 0.7 * assignment_match + 0.3 * distance_eff,
|
| 366 |
+
}
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
# ============================================================
|
| 370 |
+
# VARP COMPOSITE EVALUATOR
|
| 371 |
+
# ============================================================
|
| 372 |
+
class VARPEvaluator:
|
| 373 |
+
"""Visual-Action Reasoning Precision — composite evaluator."""
|
| 374 |
+
|
| 375 |
+
# Axis weights (sum to 1.0)
|
| 376 |
+
WEIGHTS = {
|
| 377 |
+
"spatial": 0.30,
|
| 378 |
+
"temporal": 0.20,
|
| 379 |
+
"causal": 0.25,
|
| 380 |
+
"decision": 0.25,
|
| 381 |
+
}
|
| 382 |
+
|
| 383 |
+
def __init__(self):
|
| 384 |
+
self.spatial = SpatialEvaluator()
|
| 385 |
+
self.temporal = TemporalEvaluator()
|
| 386 |
+
self.causal = CausalEvaluator()
|
| 387 |
+
self.decision = DecisionEvaluator()
|
| 388 |
+
|
| 389 |
+
def evaluate_single(self, prediction: str, ground_truth: Dict) -> Dict:
|
| 390 |
+
"""Evaluate a single prediction against ground truth."""
|
| 391 |
+
spatial_result = self.spatial.evaluate(prediction, ground_truth)
|
| 392 |
+
temporal_result = self.temporal.evaluate(prediction, ground_truth)
|
| 393 |
+
causal_result = self.causal.evaluate(prediction, ground_truth)
|
| 394 |
+
decision_result = self.decision.evaluate(prediction, ground_truth)
|
| 395 |
+
|
| 396 |
+
composite = (
|
| 397 |
+
self.WEIGHTS["spatial"] * spatial_result["score"] +
|
| 398 |
+
self.WEIGHTS["temporal"] * temporal_result["score"] +
|
| 399 |
+
self.WEIGHTS["causal"] * causal_result["score"] +
|
| 400 |
+
self.WEIGHTS["decision"] * decision_result["score"]
|
| 401 |
+
)
|
| 402 |
+
|
| 403 |
+
return {
|
| 404 |
+
"varp_score": round(composite, 4),
|
| 405 |
+
"spatial": spatial_result,
|
| 406 |
+
"temporal": temporal_result,
|
| 407 |
+
"causal": causal_result,
|
| 408 |
+
"decision": decision_result,
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
def evaluate_batch(
|
| 412 |
+
self,
|
| 413 |
+
predictions: List[Dict],
|
| 414 |
+
chains_dir: str,
|
| 415 |
+
) -> Dict:
|
| 416 |
+
"""Evaluate a batch of predictions against ground truth chains.
|
| 417 |
+
|
| 418 |
+
Args:
|
| 419 |
+
predictions: List of dicts with 'image' and 'response' keys
|
| 420 |
+
chains_dir: Directory containing ground truth chain JSON files
|
| 421 |
+
|
| 422 |
+
Returns:
|
| 423 |
+
Dict with per-sample and aggregate results
|
| 424 |
+
"""
|
| 425 |
+
results = []
|
| 426 |
+
scores = []
|
| 427 |
+
|
| 428 |
+
for pred in predictions:
|
| 429 |
+
if "error" in pred:
|
| 430 |
+
continue
|
| 431 |
+
|
| 432 |
+
# Derive chain filename from image path
|
| 433 |
+
image_path = pred.get("image", "")
|
| 434 |
+
basename = os.path.splitext(os.path.basename(image_path))[0]
|
| 435 |
+
# Remove view suffix (e.g., "_topdown" or "_r0")
|
| 436 |
+
for suffix in ["_topdown", "_ego_r0", "_ego_r1", "_ego_r2"]:
|
| 437 |
+
basename = basename.replace(suffix, "")
|
| 438 |
+
|
| 439 |
+
chain_path = os.path.join(chains_dir, f"{basename}.json")
|
| 440 |
+
if not os.path.exists(chain_path):
|
| 441 |
+
continue
|
| 442 |
+
|
| 443 |
+
with open(chain_path) as f:
|
| 444 |
+
ground_truth = json.load(f)
|
| 445 |
+
|
| 446 |
+
result = self.evaluate_single(pred["response"], ground_truth)
|
| 447 |
+
result["sample_id"] = basename
|
| 448 |
+
results.append(result)
|
| 449 |
+
scores.append(result["varp_score"])
|
| 450 |
+
|
| 451 |
+
# Aggregate
|
| 452 |
+
if not scores:
|
| 453 |
+
return {"error": "No matching ground truth chains found"}
|
| 454 |
+
|
| 455 |
+
aggregate = {
|
| 456 |
+
"total_samples": len(results),
|
| 457 |
+
"varp_mean": round(np.mean(scores), 4),
|
| 458 |
+
"varp_std": round(np.std(scores), 4),
|
| 459 |
+
"varp_min": round(min(scores), 4),
|
| 460 |
+
"varp_max": round(max(scores), 4),
|
| 461 |
+
"varp_median": round(np.median(scores), 4),
|
| 462 |
+
"per_axis": {
|
| 463 |
+
"spatial": round(np.mean([r["spatial"]["score"] for r in results]), 4),
|
| 464 |
+
"temporal": round(np.mean([r["temporal"]["score"] for r in results]), 4),
|
| 465 |
+
"causal": round(np.mean([r["causal"]["score"] for r in results]), 4),
|
| 466 |
+
"decision": round(np.mean([r["decision"]["score"] for r in results]), 4),
|
| 467 |
+
},
|
| 468 |
+
"samples": results,
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
return aggregate
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# ============================================================
|
| 475 |
+
# MAIN
|
| 476 |
+
# ============================================================
|
| 477 |
+
def main():
|
| 478 |
+
parser = argparse.ArgumentParser(description="VARP Evaluation Framework")
|
| 479 |
+
parser.add_argument("--predictions", default=None,
|
| 480 |
+
help="JSON file with model predictions")
|
| 481 |
+
parser.add_argument("--ground-truth", default="aegis_dataset/chains",
|
| 482 |
+
help="Directory with ground truth chain JSONs")
|
| 483 |
+
parser.add_argument("--pred-text", default=None,
|
| 484 |
+
help="Single prediction text (for quick eval)")
|
| 485 |
+
parser.add_argument("--gt-chain", default=None,
|
| 486 |
+
help="Single ground truth chain JSON path")
|
| 487 |
+
parser.add_argument("--output", default="varp_report.json",
|
| 488 |
+
help="Output report path")
|
| 489 |
+
args = parser.parse_args()
|
| 490 |
+
|
| 491 |
+
evaluator = VARPEvaluator()
|
| 492 |
+
|
| 493 |
+
# Single sample mode
|
| 494 |
+
if args.pred_text and args.gt_chain:
|
| 495 |
+
with open(args.gt_chain) as f:
|
| 496 |
+
gt = json.load(f)
|
| 497 |
+
result = evaluator.evaluate_single(args.pred_text, gt)
|
| 498 |
+
print(f"\nVARP Score: {result['varp_score']:.1%}")
|
| 499 |
+
print(f" Spatial: {result['spatial']['score']:.1%}")
|
| 500 |
+
print(f" Temporal: {result['temporal']['score']:.1%}")
|
| 501 |
+
print(f" Causal: {result['causal']['score']:.1%}")
|
| 502 |
+
print(f" Decision: {result['decision']['score']:.1%}")
|
| 503 |
+
return
|
| 504 |
+
|
| 505 |
+
# Batch mode
|
| 506 |
+
if args.predictions:
|
| 507 |
+
with open(args.predictions) as f:
|
| 508 |
+
predictions = json.load(f)
|
| 509 |
+
|
| 510 |
+
print(f"VARP Evaluation")
|
| 511 |
+
print(f" Predictions: {len(predictions)} samples")
|
| 512 |
+
print(f" Ground truth: {args.ground_truth}")
|
| 513 |
+
print()
|
| 514 |
+
|
| 515 |
+
report = evaluator.evaluate_batch(predictions, args.ground_truth)
|
| 516 |
+
|
| 517 |
+
if "error" in report:
|
| 518 |
+
print(f" ERROR: {report['error']}")
|
| 519 |
+
return
|
| 520 |
+
|
| 521 |
+
print(f"Results:")
|
| 522 |
+
print(f" VARP Score: {report['varp_mean']:.1%} ± {report['varp_std']:.1%}")
|
| 523 |
+
print(f" Samples evaluated: {report['total_samples']}")
|
| 524 |
+
print(f" Per-axis scores:")
|
| 525 |
+
for axis, score in report["per_axis"].items():
|
| 526 |
+
print(f" {axis:10s}: {score:.1%}")
|
| 527 |
+
|
| 528 |
+
with open(args.output, "w") as f:
|
| 529 |
+
json.dump(report, f, indent=2)
|
| 530 |
+
print(f"\n Full report: {args.output}")
|
| 531 |
+
else:
|
| 532 |
+
parser.print_help()
|
| 533 |
+
|
| 534 |
+
|
| 535 |
+
if __name__ == "__main__":
|
| 536 |
+
main()
|
aegis-reason/aegis-reason/configs/aegis_grpo.toml
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ============================================================
|
| 2 |
+
# AEGIS GRPO RL Training Configuration for cosmos-rl
|
| 3 |
+
# ============================================================
|
| 4 |
+
# Reinforcement Learning via GRPO on the SFT-trained AEGIS model
|
| 5 |
+
# Uses VARP reward function for physically-grounded feedback
|
| 6 |
+
#
|
| 7 |
+
# Prerequisites:
|
| 8 |
+
# - SFT checkpoint from aegis_sft training
|
| 9 |
+
# - 8× H100 GPUs on Nebius (4 policy + 4 rollout)
|
| 10 |
+
#
|
| 11 |
+
# Usage:
|
| 12 |
+
# cosmos-rl --config aegis_grpo.toml aegis_grpo_reward.py
|
| 13 |
+
# ============================================================
|
| 14 |
+
|
| 15 |
+
# --- Custom dataset (same prompts, no GT answers needed for RL) ---
|
| 16 |
+
[custom.dataset]
|
| 17 |
+
annotation_path = "/data/aegis/aegis_llava/annotations_train.json"
|
| 18 |
+
media_path = "/data/aegis/"
|
| 19 |
+
|
| 20 |
+
[custom.vision]
|
| 21 |
+
min_pixels = 3136
|
| 22 |
+
max_pixels = 409600
|
| 23 |
+
|
| 24 |
+
# --- VARP reward configuration ---
|
| 25 |
+
[custom.reward]
|
| 26 |
+
# Ground truth chains directory for VARP scoring
|
| 27 |
+
chains_dir = "/data/aegis/aegis_dataset/chains"
|
| 28 |
+
# Reward weights per VARP axis (should sum to 1.0)
|
| 29 |
+
spatial_weight = 0.30
|
| 30 |
+
temporal_weight = 0.20
|
| 31 |
+
causal_weight = 0.25
|
| 32 |
+
decision_weight = 0.25
|
| 33 |
+
# Bonus reward for structured output format
|
| 34 |
+
format_bonus = 0.1
|
| 35 |
+
# Penalty for overly short responses (< 100 chars)
|
| 36 |
+
brevity_penalty = -0.3
|
| 37 |
+
|
| 38 |
+
# --- Training hyperparameters ---
|
| 39 |
+
[train]
|
| 40 |
+
output_dir = "/data/aegis/outputs/aegis_grpo"
|
| 41 |
+
resume = true
|
| 42 |
+
compile = false
|
| 43 |
+
epoch = 2 # RL typically needs fewer epochs
|
| 44 |
+
train_batch_per_replica = 4 # Smaller batch for RL (more GPU per sample)
|
| 45 |
+
optm_lr = 5e-7 # Much lower LR for RL than SFT
|
| 46 |
+
optm_weight_decay = 0.01
|
| 47 |
+
optm_warmup_steps = 0.03
|
| 48 |
+
optm_decay_type = "cosine"
|
| 49 |
+
optm_grad_norm_clip = 1.0
|
| 50 |
+
seed = 42
|
| 51 |
+
|
| 52 |
+
# --- Policy model (start from SFT checkpoint) ---
|
| 53 |
+
[policy]
|
| 54 |
+
# Point to the best SFT checkpoint
|
| 55 |
+
model_name_or_path = "/data/aegis/outputs/aegis_sft_2b/checkpoints/step_250/policy"
|
| 56 |
+
model_max_length = 4096
|
| 57 |
+
model_gradient_checkpointing = true
|
| 58 |
+
|
| 59 |
+
# --- Logging ---
|
| 60 |
+
[logging]
|
| 61 |
+
logger = ['console', 'wandb']
|
| 62 |
+
project_name = "aegis_reason"
|
| 63 |
+
experiment_name = "grpo/aegis_disaster_rescue_v1"
|
| 64 |
+
|
| 65 |
+
# --- GRPO RL training policy ---
|
| 66 |
+
[train.train_policy]
|
| 67 |
+
type = "grpo"
|
| 68 |
+
mini_batch = 2
|
| 69 |
+
dataloader_num_workers = 4
|
| 70 |
+
|
| 71 |
+
# GRPO-specific parameters
|
| 72 |
+
num_generations = 4 # G=4 completions per prompt
|
| 73 |
+
kl_beta = 0.05 # Positive KL to prevent overfitting
|
| 74 |
+
# (VideoPhy-2 recipe: crucial for stability)
|
| 75 |
+
clip_epsilon = 0.2 # PPO-style clipping
|
| 76 |
+
temperature = 0.7 # Sampling temperature for rollouts
|
| 77 |
+
max_new_tokens = 768 # Max tokens per generation
|
| 78 |
+
top_p = 0.9
|
| 79 |
+
|
| 80 |
+
[train.train_policy.dataset]
|
| 81 |
+
test_size = 0
|
| 82 |
+
|
| 83 |
+
# --- Checkpointing ---
|
| 84 |
+
[train.ckpt]
|
| 85 |
+
enable_checkpoint = true
|
| 86 |
+
save_freq = 25 # Save every 25 steps (RL is expensive)
|
| 87 |
+
save_mode = "sync"
|
| 88 |
+
max_keep = 8
|
| 89 |
+
export_safetensors = true
|
| 90 |
+
|
| 91 |
+
# --- Parallelism ---
|
| 92 |
+
# RL needs separate policy + rollout GPUs
|
| 93 |
+
# 8 GPUs total: 4 for policy training, 4 for rollout inference
|
| 94 |
+
[policy.parallelism]
|
| 95 |
+
tp_size = 1
|
| 96 |
+
cp_size = 1
|
| 97 |
+
dp_shard_size = 4 # 4 GPUs for policy (FSDP)
|
| 98 |
+
pp_size = 1
|
| 99 |
+
|
| 100 |
+
[rollout.parallelism]
|
| 101 |
+
tp_size = 1
|
| 102 |
+
dp_size = 4 # 4 GPUs for rollout
|
aegis-reason/aegis-reason/configs/aegis_sft.toml
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# ============================================================
|
| 2 |
+
# AEGIS SFT Training Configuration for cosmos-rl
|
| 3 |
+
# ============================================================
|
| 4 |
+
# Fine-tune Cosmos Reason 2 on AEGIS disaster rescue reasoning
|
| 5 |
+
# Designed for Nebius H100 cluster (8 GPUs)
|
| 6 |
+
#
|
| 7 |
+
# Usage:
|
| 8 |
+
# cosmos-rl --config aegis_sft.toml aegis_dataloader.py
|
| 9 |
+
# ============================================================
|
| 10 |
+
|
| 11 |
+
# --- Custom dataset settings ---
|
| 12 |
+
[custom.dataset]
|
| 13 |
+
# Path to the LLaVA-format annotation file
|
| 14 |
+
annotation_path = "/data/aegis/aegis_llava/annotations_train.json"
|
| 15 |
+
# Base path for media files (images). Set to "" if annotation paths are absolute
|
| 16 |
+
media_path = "/data/aegis/"
|
| 17 |
+
|
| 18 |
+
[custom.vision]
|
| 19 |
+
# Image processing for Cosmos Reason 2 (Qwen3-VL architecture)
|
| 20 |
+
# Our frames are 640x640 — well within the per-frame budget
|
| 21 |
+
min_pixels = 3136 # 56×56 minimum (4 patches)
|
| 22 |
+
max_pixels = 409600 # 640×640 = 409,600 — matches our exact frame size
|
| 23 |
+
# nframes = 1 # Not needed for single-image SFT
|
| 24 |
+
|
| 25 |
+
# --- Training hyperparameters ---
|
| 26 |
+
[train]
|
| 27 |
+
output_dir = "/data/aegis/outputs/aegis_sft"
|
| 28 |
+
resume = true
|
| 29 |
+
compile = false
|
| 30 |
+
|
| 31 |
+
# 5 epochs — our dataset is ~12K samples, small enough to train multiple passes
|
| 32 |
+
# without severe overfitting (the Uber recipe used 3 epochs on 1.1M samples)
|
| 33 |
+
epoch = 5
|
| 34 |
+
|
| 35 |
+
# Per-GPU batch size. With 8 GPUs and mini_batch=4, effective batch = 8 × 4 × 4 = 128
|
| 36 |
+
train_batch_per_replica = 16
|
| 37 |
+
|
| 38 |
+
# Learning rate — conservative for domain adaptation
|
| 39 |
+
# Uber recipe: 2e-7 for 1.1M samples. We use 5e-6 for our smaller ~12K dataset.
|
| 40 |
+
# Higher LR compensates for fewer total training steps.
|
| 41 |
+
optm_lr = 5e-6
|
| 42 |
+
optm_weight_decay = 0.01
|
| 43 |
+
optm_warmup_steps = 0.05 # 5% warmup
|
| 44 |
+
optm_decay_type = "cosine"
|
| 45 |
+
optm_grad_norm_clip = 1.0
|
| 46 |
+
seed = 42
|
| 47 |
+
|
| 48 |
+
# --- Model configuration ---
|
| 49 |
+
[policy]
|
| 50 |
+
# Start with 2B for faster iteration; switch to 8B for final quality
|
| 51 |
+
model_name_or_path = "nvidia/Cosmos-Reason2-2B"
|
| 52 |
+
|
| 53 |
+
# Max sequence length — our reasoning chains are ~300-600 tokens,
|
| 54 |
+
# plus system prompt + user prompt + image tokens ≈ 2K total
|
| 55 |
+
model_max_length = 4096
|
| 56 |
+
|
| 57 |
+
# Gradient checkpointing for memory efficiency
|
| 58 |
+
model_gradient_checkpointing = true
|
| 59 |
+
|
| 60 |
+
# --- Logging ---
|
| 61 |
+
[logging]
|
| 62 |
+
logger = ['console', 'wandb']
|
| 63 |
+
project_name = "aegis_reason"
|
| 64 |
+
experiment_name = "sft/aegis_disaster_rescue_v1"
|
| 65 |
+
|
| 66 |
+
# --- SFT training policy ---
|
| 67 |
+
[train.train_policy]
|
| 68 |
+
type = "sft"
|
| 69 |
+
mini_batch = 4
|
| 70 |
+
dataloader_num_workers = 4
|
| 71 |
+
dataloader_prefetch_factor = 4
|
| 72 |
+
|
| 73 |
+
# conversation column in LLaVA format
|
| 74 |
+
conversation_column_name = "conversations"
|
| 75 |
+
|
| 76 |
+
[train.train_policy.dataset]
|
| 77 |
+
test_size = 0 # We handle our own val split externally
|
| 78 |
+
|
| 79 |
+
# --- Checkpointing ---
|
| 80 |
+
[train.ckpt]
|
| 81 |
+
enable_checkpoint = true
|
| 82 |
+
save_freq = 50 # Save every 50 steps for checkpoint selection
|
| 83 |
+
save_mode = "sync"
|
| 84 |
+
max_keep = 10
|
| 85 |
+
export_safetensors = true
|
| 86 |
+
|
| 87 |
+
# --- Parallelism (8× H100 on Nebius) ---
|
| 88 |
+
[policy.parallelism]
|
| 89 |
+
tp_size = 1 # No tensor parallelism needed for 2B model
|
| 90 |
+
cp_size = 1 # No context parallelism
|
| 91 |
+
dp_shard_size = 8 # 8-way data parallel (FSDP)
|
| 92 |
+
pp_size = 1 # No pipeline parallelism
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# ============================================================
|
| 96 |
+
# VARIANT: 8B model (uncomment to use larger model)
|
| 97 |
+
# ============================================================
|
| 98 |
+
# [policy]
|
| 99 |
+
# model_name_or_path = "nvidia/Cosmos-Reason2-8B"
|
| 100 |
+
# model_max_length = 4096
|
| 101 |
+
# model_gradient_checkpointing = true
|
| 102 |
+
#
|
| 103 |
+
# [policy.parallelism]
|
| 104 |
+
# tp_size = 2 # Tensor parallel across 2 GPUs for 8B
|
| 105 |
+
# cp_size = 1
|
| 106 |
+
# dp_shard_size = 4 # 4-way data parallel (8 GPUs / tp=2)
|
| 107 |
+
# pp_size = 1
|
| 108 |
+
#
|
| 109 |
+
# [train]
|
| 110 |
+
# train_batch_per_replica = 8 # Smaller batch for 8B
|
| 111 |
+
# optm_lr = 2e-6 # Slightly lower LR for larger model
|
| 112 |
+
# epoch = 3 # Fewer epochs to avoid overfitting
|
aegis-reason/aegis-reason/demo/aegis_dashboard.jsx
ADDED
|
@@ -0,0 +1,291 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { useState } from "react";
|
| 2 |
+
|
| 3 |
+
// Embedded demo samples (3 disaster rescue scenarios with reasoning chains)
|
| 4 |
+
const SAMPLES = [{"id":"seed001_b0.3_no_intel_step000","step":0,"rescued":0,"survivors":7,"hazards":5,"spatial":"Grid: 20\u00d720. 7 survivors remaining. 5 flood cells. Robot 0: position (17,0), sector 13. Robot 1: position (13,9), sector 10. Robot 2: position (9,7), sector 6. Survivor at (1,12), sector 3. Nearest robot: 2 (distance 13). Survivor at (4,9), sector 2. Nearest robot: 2 (distance 7). Survivor at (5,18), sector 8. Nearest robot: 2 (distance 15). Survivor at (6,18), sector 8. Nearest robot: 2 (distance 14). Survivor at (7,13), sector 7. Nearest robot: 2 (distance 8). Survivor at (11,10), sector 11. Nearest robot: 1 (distance 3). Survivor at (14,18), sector 12. Nearest robot: 1 (distance 10).","temporal":"Current step: 0. Flood cells: 5. Frontier cells: 5. Flood expanding stationary. Predicted flood cells at step 3: ~6. Predicted flood cells at step 5: ~7. Predicted flood cells at step 10: ~9.","causal":"Survivor (1,12): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 2 at distance 13. Survivor (4,9): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 2 at distance 7. Survivor (5,18): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 2 at distance 15. Survivor (6,18): urgency HIGH \u2014 flood approaching (4 cells). Nearest robot: 2 at distance 14. Survivor (7,13): urgency HIGH \u2014 flood approaching (4 cells). Nearest robot: 2 at distance 8. Survivor (11,10): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 1 at distance 3. Survivor (14,18): urgency STANDARD \u2014 accessible, no immediate threat. Nearest robot: 1 at distance 10. Causal factors: rescue probability depends on (1) robot-survivor distance, (2) flood proximity to survivor, (3) path traversability, (4) competing allocation demands from other survivors.","decision":"Recommended: Robot 1 (13,9) \u2192 survivor (11,10), sector 11, distance 3 steps. Recommended: Robot 2 (9,7) \u2192 survivor (4,9), sector 2, distance 7 steps. Recommended: Robot 0 (17,0) \u2192 survivor (14,18), sector 12, distance 21 steps. Survivors remaining to rescue: 7. Target: 5 total.","img":"iVBORw0KGgoAAAANSUhEUgAAAoAAAAKACAIAAACDr150AAA7yklEQVR4nO3df3xcVZ3/8TOTmWQynWSSpr/oT/q7BRqItAY1gy2CCoLiIiLiIkqiq19dFUFR11+oiCysftVl1dYVcPWrLC4ILMiitutEJaYlJWmhQKFt+pM2v5MmaTKZ+f5x28t0kkzmx71zzrn39Xzw4DFJZj73zL3pvHPOPedeT319vQAAAIXlE0I0bd1u3wbCoUDvwDD1ZdWvXXsex9fB9Tm+zq5fgOPbeFfUvvp1N0e03v921/fZVxoAoL6Fm5rsKNteX2tHWSfxym4AAABuRAADACABAQwAgAQEMAAAEhDAAABIQAADAJxpZMGCtpbmkblnyG7IxNItQyotLf34xz7y1ksuLisra21t+/FPNrVsf9b4UVlZ2Z//9Mdrr7t+53PPF6Sdqeo/fMO1115TXlb2zDPPfPlr3zh69JiUZgCAG3k97T9+vfGwqH+0ePdA5W/afa/auGRWlmMfvqHj2mviZWXTmrfO+8a3/OOy5sSZi176z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BwHtUDmI4vAMCRlB6CJn0BAE6laA+YYWcAgLMpF8BELwDADdQKYMacAQAuoUoA0/EFALiK5AA2clcQvQAAl5EWwHR5AQBuVugApssLAIAoWACTuwAAJPPtq6npK6sQNkSjEbqxgH9weJTcBQAgmW9RS8uRrdtFUifVlFVqTvbycCjgs/luIQAAaOe1IejxcTs+U9OgjwsAQObSnQMmUwEAsInSN2MAAMCpCGAAACQggAEAkIAABgBAAgIYAAAJCGAAACQggAEAkIAABgBAAgIYAAAJCGAAACQggAEAkIAABgBAAgIYAAAJCGAAACT4/xP+vUp/tHLrAAAAAElFTkSuQmCC"},{"id":"seed005_b2.0_no_intel_step004","step":4,"rescued":2,"survivors":5,"hazards":18,"spatial":"Grid: 20\u00d720. 5 survivors remaining. 18 flood cells. Robot 0: position (12,11), sector 11. Robot 1: position (10,4), sector 9. Robot 2: position (16,6), sector 14. Survivor at (1,15), sector 4. Nearest robot: 0 (distance 15). Survivor at (12,15), sector 12. Nearest robot: 0 (distance 4). Survivor at (13,11), sector 11. Nearest robot: 0 (distance 1). Survivor at (16,12), sector 15. Nearest robot: 0 (distance 5). Survivor at (18,9), sector 14. Nearest robot: 2 (distance 5).","temporal":"Current step: 4. Flood cells: 18. Frontier cells: 18. Flood expanding stationary. Predicted flood cells at step 7: ~22. Predicted flood cells at step 9: ~25. Predicted flood cells at step 14: ~32.","causal":"Survivor (1,15): urgency CRITICAL \u2014 flood frontier is 2 cells away. Nearest robot: 0 at distance 15. Survivor (12,15): urgency STANDARD \u2014 accessible, no immediate threat. Nearest robot: 0 at distance 4. Survivor (13,11): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 0 at distance 1. Survivor (16,12): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 0 at distance 5. Survivor (18,9): urgency CRITICAL \u2014 flood frontier is 1 cells away. Nearest robot: 2 at distance 5. Causal factors: rescue probability depends on (1) robot-survivor distance, (2) flood proximity to survivor, (3) path traversability, (4) competing allocation demands from other survivors.","decision":"Recommended: Robot 0 (12,11) \u2192 survivor (13,11), sector 11, distance 1 steps. Recommended: Robot 2 (16,6) \u2192 survivor (18,9), sector 14, distance 5 steps. Recommended: Robot 1 (10,4) \u2192 survivor (12,15), sector 12, distance 13 steps. Survivors remaining to rescue: 3. Target: 5 total.","img":"iVBORw0KGgoAAAANSUhEUgAAAoAAAAKACAIAAACDr150AABDG0lEQVR4nO3de3wcZ33v8WdXK2klr7WS5XtsK77EUULsRLWNIHhBAtzWQM6h5U64BCLnFA4lXAINIZA2QBogXE6aUk6dc0IC7SkUSiAlhhpqt5vSuLYjI9uJ4yS2JfmWxCtZa1laS6vd88fY4/XetJeZeeZ55vN+5fWKLK2eeTSX57u/Z2ZnfD09PQIAADgrIITYsWuPfQsIh4Ijownal9V+59rr2L4at8/21bt9tq/e7fvtaxoAABRCAAMAIAEBDACABAQwAAASEMAAAEhAAAMAIAEBDADQ08TixXt7d04sXCC7I/kVC+CGhoZPf+rWX2157LdPbP/ud/6q47przR/NnDmzr3fnK66+yv4eFvOpT94ajUbf+fa3ye0GAHhKuqZmb+9O479nfvOr/m9+/VzbEtmdst7oVVcduf9bT//bb5759S+P3n1XsnVW7mvOXd62b/eOc5e3Gf88fvtnzTWzt3fn8ds/W6T9QJGf3fn529uWLP7IRz9+8sUXr2q/8n03vqd3z++q+WOs9cp1azuuu3ZyclJ2RwDAixbf+cXmX2yZXLDg6J9/4cgD/2vl297lm5iQ3SkrDd5446yf/mzxF/481dg4+JW7+7953/IPfjjrNadufG/oif+oP9Jvfif8m39dctufldJ+wQD2+/0b3vD6z33+C4cOHxZC7H6qd/dTvUKIefPmbv3lL4zX/L+/e8T44jWvff2ZM2eMr99343tufM+7Z89uPXTo8Lfvf+Dpfb8TQjxw/7eGhoZnz2595bq1R48d+/JX7t21+6kSV0FeM2fO/OKdd3z8E5/+xx/+XTXtAACqUXvixNzv/u2h/7s5sXx5wzPPCCFO3fie2HvenZzd2tjfP+db94ee3HH+pT7fi//zI8M3vGVqxowZTz218O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IFDHhFoWQqlHPC5nOo8e4uo/1CLyBKobfsAKYIBrymyPFunEMtktBVLtfac7SMXVALFTCAaZBqgB38ud8yimCnOwIAVaD8hXLyBDAAALBb/gCmCAagEMpfqIgKGAAACQoGMEUwACVQ/kJRVMAAAEhQLIApggG4HOUv1EUFDACABNMEMEUwANei/IXSqIABAJBg+gCmCAbgQpS/UB0VMAAAEpQUwBTBAFyF8hcaoAIGAECC/w8eWrvEq9g8AAAAAABJRU5ErkJggg=="},{"id":"seed002_b2.0_no_intel_step006","step":6,"rescued":3,"survivors":4,"hazards":18,"spatial":"Grid: 20\u00d720. 4 survivors remaining. 18 flood cells. Robot 0: position (2,6), sector 2. Robot 1: position (7,3), sector 5. Robot 2: position (17,7), sector 14. Survivor at (6,10), sector 7. Nearest robot: 0 (distance 8). Survivor at (10,11), sector 11. Nearest robot: 1 (distance 11). Survivor at (17,11), sector 15. Nearest robot: 2 (distance 4). Survivor at (19,7), sector 14. Nearest robot: 2 (distance 2).","temporal":"Current step: 6. Flood cells: 18. Frontier cells: 17. Flood expanding stationary. Predicted flood cells at step 9: ~22. Predicted flood cells at step 11: ~24. Predicted flood cells at step 16: ~31.","causal":"Survivor (6,10): urgency STANDARD \u2014 accessible, no immediate threat. Nearest robot: 0 at distance 8. Survivor (10,11): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 1 at distance 11. Survivor (17,11): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 2 at distance 4. Survivor (19,7): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 2 at distance 2. Causal factors: rescue probability depends on (1) robot-survivor distance, (2) flood proximity to survivor, (3) path traversability, (4) competing allocation demands from other survivors.","decision":"Recommended: Robot 2 (17,7) \u2192 survivor (19,7), sector 14, distance 2 steps. Recommended: Robot 0 (2,6) \u2192 survivor (6,10), sector 7, distance 8 steps. Recommended: Robot 1 (7,3) \u2192 survivor (10,11), sector 11, distance 11 steps. Survivors remaining to rescue: 1. Target: 5 total.","img":"iVBORw0KGgoAAAANSUhEUgAAAoAAAAKACAIAAACDr150AAA9QElEQVR4nO3de3xcdZ3/8c9MJskknWaSpnd6hRbKpaGxrUG2owlStV7WC6IirItLqgu6i66si/dddRERvLCs69quCLr+VkRFRIpUbWUqEtuSkLQ0QGmbSy/QTtOkaZImk5nfH6cdhkkymcs58z3fc17PBw8eaTLzOd/MmTnvfL7n5mlsbBQAcKiO2tqFzc2qRwGMwyciTTtarFtAMODv7R+ivqr6datWsH4dXJ/1O3n9HS3PN9RXbNlqVX3WL/Vz5bWuNAAAmAgBDACAAgQwAIer2LK1r6Fe9SiAVAQwAAAKEMAAAChAAANwPmahYUMEMADAmYbnz29r3j48d47qgYzPl+ZnZWVlN934kTetvXLq1KmtrW3//f2NzS3PGD+aOnXqn574wzXXfmj3s3sKMs5Ul7/uso9/7MalS5ccPnToi//6lZZnWpUMAwBcKF5UtGvHU8bXvuPHy59pnf2d/yjt6FQ7KtMNzZvX/cFrT675KxGZ8nTz7G/fXdJ9MOUxpxctfOHnDyy96n2lBzpE5NCtn468/+rET6t/+rO5t98xUf10HfDnP3dr7YpLb7zpH69801s3bPzBdddek9evYp4Vl9bcc/e3Hn98c/0Vaz/zmc801L9B9YgA2B2z0Kab//kvLq9dveS662NTphy45zvxkhLVIzJZ9/vfPzX8p/PfffXS930w7vEeuOfusY85du0HA9v+ZKSvIfj7PyyvXW38lyZ9JU0H7PV6177xis987gv79u8XkZ1PN+98ullEZs2aufmx3xiP+X//e7/xxV+9/oqTJ08aX1937TXXXvOB6dOr9+3b/+2773l21zMics/d3zp+vGf69OrXrl7VffDgV//99h07n87qhUj2kfU3bNn6xx/e/2MR6e7u/tZ3/iPnUgCAfBQfPjzze9/f94MNQ+edV7Znj4gcu/aayDUfiE6vLu/omPGtuwNPNZ15qMfz0sdu7HnH20enTJny9NNzv/HNkq4u4yenFy448smb+1et9A6drnx00+z/+E/PyIiIdN759aKeE+f8+9dEJFpZuWfL5qUfuNb/3PPGUl649prhadNK9+2fffc9iaXEyssPfuGzffVvKOrtm/HD+/L51ZbcdVfiSljTfvHLA/d8J1o9zRc5nnhAtLLyxDvetujjN+dWf8IOOBaLDQ8Pr1q10uPxJH//pZderqld/Vevv0JErrn2QzW1q2tqVyfS933vveqDH3j/P9/62VD9lffed//d375r3rx5xo/++h1ve3TTY/VvfPPvfveHb931jfLy8uSyd9x+W2vz9qlTp04+Yq935Wtq/2DNheUAANnyxGIiEi8tEZHj770q8oH3z7/1sxfWXznvJz/p+PZdw/PnGw/rfdOVkfdetegfbr5w7Vuq/++Bnne81fh+rKxs//e+6+0/df5737/06g+UdHUPLluWfonGUi740pcurL9yxn33Jy/lyMdvHDz//KVXf+Dcxo8cv+o9KU/svP22tubtoxlkTbKR2bOOX31VWftzvp4TrxrG+95buv/AlB07k7958nWX7X5qW/tvHz34+c+mX1C6Keg77vzW1Ve957FHH/7ql7/05jdd6fOl22Fs+Pu/X3/3Pd/dtWv30NDQY7/d3Nq2q6GhwfjRM61tj/xmU39///e+v9HjkSvfeMWk1cYVCATKysoqg5UPPvCT7U9tu++++954RX1upQC4CrPQVohOn/7y311feuBA2a7dIvLS36+fdc93y3ft9g4NTf/978vadvWufaPxyOG5c32RiP/5F7yDg1Of/POs7/638f2ed74jXlw878tfLT7ykq+np/pnD5a3taVfqLGUqXv2eIeGgr/d/MpSPJ6ed71zxr33lXQfLOk+OOMHP8zztzv5+lBb8/b2TY8Mz5mz6OM3SyyW+FG8pCTyvqun/+jHyY8vOXRowT/feuEVb1pwy6dPraztuv3f0xRPF8AP//qRdW9/1w/uvc/v9//bl77wo/t+UFpamubxVVVV06urb7/tKy07m1p2Nj3z9F9Wr1o5e/Zs46f79+83vohGo90HDy6YPy/5uZ++9bPJnXS6EXs8InLdtdd86V+/8vqGtY888sidd9x+3rmLJ30iAMBEXV/9clvz9j2bN8X9/vOub/REo9Gqqmh1dfdtX9m1s6ltZ9O2J544tWrl8Ny5xuMrfv+H0arKvf97/0s3fbT/dZeJ90wADS1ZUvbcc57h4Qy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8Ly4chAXA1ghgOER8gq8BwJ5MDmBmoaHGypVGHxxP9L60vyg45p+RFc4DhoMQugD0wRQ0AAAKmB/AzEIDcCHmn5EtOmAAABQggAEAUMCSAGYWGoCrMP+MHNABAwCgAAEMAIACVgUws9AAXIL5Z+SGDhgAAAUIYAAAFPj/Iu5VHeJ9Jl4AAAAASUVORK5CYII="}];
|
| 5 |
+
|
| 6 |
+
const CHAIN_COLORS = {
|
| 7 |
+
spatial: { bg: "#1a2744", border: "#3b82f6", text: "#93c5fd", icon: "🗺️", label: "SPATIAL GROUNDING" },
|
| 8 |
+
temporal: { bg: "#1a3328", border: "#22c55e", text: "#86efac", icon: "⏱️", label: "TEMPORAL DYNAMICS" },
|
| 9 |
+
causal: { bg: "#3b1a1a", border: "#ef4444", text: "#fca5a5", icon: "⚡", label: "CAUSAL REASONING" },
|
| 10 |
+
decision: { bg: "#2d1f0e", border: "#f59e0b", text: "#fcd34d", icon: "🎯", label: "DECISION" },
|
| 11 |
+
};
|
| 12 |
+
|
| 13 |
+
function ChainPanel({ type, text, expanded, onToggle }) {
|
| 14 |
+
const c = CHAIN_COLORS[type];
|
| 15 |
+
return (
|
| 16 |
+
<div
|
| 17 |
+
style={{
|
| 18 |
+
background: c.bg,
|
| 19 |
+
border: `1px solid ${c.border}`,
|
| 20 |
+
borderRadius: 8,
|
| 21 |
+
padding: "12px 16px",
|
| 22 |
+
cursor: "pointer",
|
| 23 |
+
transition: "all 0.2s",
|
| 24 |
+
}}
|
| 25 |
+
onClick={onToggle}
|
| 26 |
+
>
|
| 27 |
+
<div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
|
| 28 |
+
<div style={{ display: "flex", alignItems: "center", gap: 8 }}>
|
| 29 |
+
<span style={{ fontSize: 18 }}>{c.icon}</span>
|
| 30 |
+
<span style={{ color: c.text, fontWeight: 700, fontSize: 13, letterSpacing: "0.05em", fontFamily: "'JetBrains Mono', monospace" }}>
|
| 31 |
+
{c.label}
|
| 32 |
+
</span>
|
| 33 |
+
</div>
|
| 34 |
+
<span style={{ color: c.text, fontSize: 12, opacity: 0.7 }}>{expanded ? "▼" : "▶"}</span>
|
| 35 |
+
</div>
|
| 36 |
+
{expanded && (
|
| 37 |
+
<div
|
| 38 |
+
style={{
|
| 39 |
+
marginTop: 10,
|
| 40 |
+
color: "#e2e8f0",
|
| 41 |
+
fontSize: 12.5,
|
| 42 |
+
lineHeight: 1.6,
|
| 43 |
+
fontFamily: "'JetBrains Mono', monospace",
|
| 44 |
+
whiteSpace: "pre-wrap",
|
| 45 |
+
wordBreak: "break-word",
|
| 46 |
+
borderTop: `1px solid ${c.border}40`,
|
| 47 |
+
paddingTop: 10,
|
| 48 |
+
}}
|
| 49 |
+
>
|
| 50 |
+
{text}
|
| 51 |
+
</div>
|
| 52 |
+
)}
|
| 53 |
+
</div>
|
| 54 |
+
);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
function StatBadge({ label, value, color }) {
|
| 58 |
+
return (
|
| 59 |
+
<div style={{
|
| 60 |
+
background: "#0f172a",
|
| 61 |
+
border: "1px solid #334155",
|
| 62 |
+
borderRadius: 6,
|
| 63 |
+
padding: "8px 14px",
|
| 64 |
+
textAlign: "center",
|
| 65 |
+
minWidth: 80,
|
| 66 |
+
}}>
|
| 67 |
+
<div style={{ color: "#94a3b8", fontSize: 10, textTransform: "uppercase", letterSpacing: "0.1em", fontFamily: "'JetBrains Mono', monospace" }}>{label}</div>
|
| 68 |
+
<div style={{ color: color || "#f1f5f9", fontSize: 22, fontWeight: 800, fontFamily: "'JetBrains Mono', monospace", marginTop: 2 }}>{value}</div>
|
| 69 |
+
</div>
|
| 70 |
+
);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
function VARPBar({ label, score, color }) {
|
| 74 |
+
return (
|
| 75 |
+
<div style={{ display: "flex", alignItems: "center", gap: 8, marginBottom: 6 }}>
|
| 76 |
+
<span style={{ color: "#94a3b8", fontSize: 11, width: 70, fontFamily: "'JetBrains Mono', monospace" }}>{label}</span>
|
| 77 |
+
<div style={{ flex: 1, height: 8, background: "#1e293b", borderRadius: 4, overflow: "hidden" }}>
|
| 78 |
+
<div style={{
|
| 79 |
+
width: `${Math.round(score * 100)}%`,
|
| 80 |
+
height: "100%",
|
| 81 |
+
background: color,
|
| 82 |
+
borderRadius: 4,
|
| 83 |
+
transition: "width 0.5s ease",
|
| 84 |
+
}} />
|
| 85 |
+
</div>
|
| 86 |
+
<span style={{ color: "#e2e8f0", fontSize: 11, width: 35, textAlign: "right", fontFamily: "'JetBrains Mono', monospace" }}>
|
| 87 |
+
{Math.round(score * 100)}%
|
| 88 |
+
</span>
|
| 89 |
+
</div>
|
| 90 |
+
);
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
export default function AEGISDashboard() {
|
| 94 |
+
const [selectedIdx, setSelectedIdx] = useState(0);
|
| 95 |
+
const [expanded, setExpanded] = useState({ spatial: true, temporal: false, causal: false, decision: false });
|
| 96 |
+
|
| 97 |
+
const sample = SAMPLES[selectedIdx];
|
| 98 |
+
|
| 99 |
+
const toggleChain = (key) => setExpanded((prev) => ({ ...prev, [key]: !prev[key] }));
|
| 100 |
+
|
| 101 |
+
// Simulated VARP scores (oracle GT should be ~97%)
|
| 102 |
+
const varpScores = {
|
| 103 |
+
spatial: 0.95 + Math.random() * 0.05,
|
| 104 |
+
temporal: 0.90 + Math.random() * 0.10,
|
| 105 |
+
causal: 0.85 + Math.random() * 0.10,
|
| 106 |
+
decision: 0.92 + Math.random() * 0.08,
|
| 107 |
+
};
|
| 108 |
+
const varpComposite = 0.30 * varpScores.spatial + 0.20 * varpScores.temporal + 0.25 * varpScores.causal + 0.25 * varpScores.decision;
|
| 109 |
+
|
| 110 |
+
return (
|
| 111 |
+
<div style={{
|
| 112 |
+
minHeight: "100vh",
|
| 113 |
+
background: "#0a0e1a",
|
| 114 |
+
color: "#e2e8f0",
|
| 115 |
+
fontFamily: "'JetBrains Mono', -apple-system, sans-serif",
|
| 116 |
+
}}>
|
| 117 |
+
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700;800&display=swap" rel="stylesheet" />
|
| 118 |
+
|
| 119 |
+
{/* Header */}
|
| 120 |
+
<div style={{
|
| 121 |
+
background: "linear-gradient(135deg, #0f172a 0%, #1a1a2e 50%, #16213e 100%)",
|
| 122 |
+
borderBottom: "2px solid #f59e0b",
|
| 123 |
+
padding: "16px 24px",
|
| 124 |
+
display: "flex",
|
| 125 |
+
alignItems: "center",
|
| 126 |
+
justifyContent: "space-between",
|
| 127 |
+
}}>
|
| 128 |
+
<div style={{ display: "flex", alignItems: "center", gap: 12 }}>
|
| 129 |
+
<div style={{
|
| 130 |
+
width: 36, height: 36, borderRadius: "50%",
|
| 131 |
+
background: "linear-gradient(135deg, #f59e0b, #ef4444)",
|
| 132 |
+
display: "flex", alignItems: "center", justifyContent: "center",
|
| 133 |
+
fontSize: 18,
|
| 134 |
+
}}>🛡️</div>
|
| 135 |
+
<div>
|
| 136 |
+
<div style={{ fontSize: 18, fontWeight: 800, letterSpacing: "0.05em", color: "#f59e0b" }}>
|
| 137 |
+
AEGIS-REASON
|
| 138 |
+
</div>
|
| 139 |
+
<div style={{ fontSize: 10, color: "#94a3b8", letterSpacing: "0.1em" }}>
|
| 140 |
+
DISASTER RESCUE REASONING · COSMOS REASON 2
|
| 141 |
+
</div>
|
| 142 |
+
</div>
|
| 143 |
+
</div>
|
| 144 |
+
<div style={{
|
| 145 |
+
background: "#1e293b",
|
| 146 |
+
border: "1px solid #f59e0b40",
|
| 147 |
+
borderRadius: 6,
|
| 148 |
+
padding: "6px 12px",
|
| 149 |
+
fontSize: 11,
|
| 150 |
+
color: "#fcd34d",
|
| 151 |
+
}}>
|
| 152 |
+
COSMOS COOKOFF 2026
|
| 153 |
+
</div>
|
| 154 |
+
</div>
|
| 155 |
+
|
| 156 |
+
{/* Scenario Selector */}
|
| 157 |
+
<div style={{ padding: "12px 24px", display: "flex", gap: 8, background: "#0f1629" }}>
|
| 158 |
+
{SAMPLES.map((s, i) => (
|
| 159 |
+
<button
|
| 160 |
+
key={s.id}
|
| 161 |
+
onClick={() => setSelectedIdx(i)}
|
| 162 |
+
style={{
|
| 163 |
+
background: i === selectedIdx ? "#1e3a5f" : "#0f172a",
|
| 164 |
+
border: `1px solid ${i === selectedIdx ? "#3b82f6" : "#334155"}`,
|
| 165 |
+
borderRadius: 6,
|
| 166 |
+
padding: "8px 14px",
|
| 167 |
+
color: i === selectedIdx ? "#93c5fd" : "#64748b",
|
| 168 |
+
cursor: "pointer",
|
| 169 |
+
fontSize: 11,
|
| 170 |
+
fontFamily: "'JetBrains Mono', monospace",
|
| 171 |
+
transition: "all 0.2s",
|
| 172 |
+
}}
|
| 173 |
+
>
|
| 174 |
+
Step {s.step} · B={s.id.match(/b([\d.]+)/)?.[1] || "?"} · {s.rescued}/{s.rescued + s.survivors} rescued
|
| 175 |
+
</button>
|
| 176 |
+
))}
|
| 177 |
+
</div>
|
| 178 |
+
|
| 179 |
+
{/* Main Content */}
|
| 180 |
+
<div style={{ display: "flex", gap: 16, padding: "16px 24px", flexWrap: "wrap" }}>
|
| 181 |
+
|
| 182 |
+
{/* Left: Frame + Stats */}
|
| 183 |
+
<div style={{ flex: "1 1 380px", minWidth: 320 }}>
|
| 184 |
+
{/* Frame */}
|
| 185 |
+
<div style={{
|
| 186 |
+
background: "#0f172a",
|
| 187 |
+
border: "1px solid #334155",
|
| 188 |
+
borderRadius: 8,
|
| 189 |
+
padding: 8,
|
| 190 |
+
marginBottom: 12,
|
| 191 |
+
}}>
|
| 192 |
+
<img
|
| 193 |
+
src={`data:image/png;base64,${sample.img}`}
|
| 194 |
+
alt="Disaster scenario"
|
| 195 |
+
style={{
|
| 196 |
+
width: "100%",
|
| 197 |
+
borderRadius: 6,
|
| 198 |
+
imageRendering: "pixelated",
|
| 199 |
+
}}
|
| 200 |
+
/>
|
| 201 |
+
<div style={{
|
| 202 |
+
marginTop: 8,
|
| 203 |
+
fontSize: 10,
|
| 204 |
+
color: "#64748b",
|
| 205 |
+
textAlign: "center",
|
| 206 |
+
}}>
|
| 207 |
+
{sample.id} · 640×640 top-down view
|
| 208 |
+
</div>
|
| 209 |
+
</div>
|
| 210 |
+
|
| 211 |
+
{/* Stats Row */}
|
| 212 |
+
<div style={{ display: "flex", gap: 8, flexWrap: "wrap", marginBottom: 12 }}>
|
| 213 |
+
<StatBadge label="Step" value={sample.step} color="#93c5fd" />
|
| 214 |
+
<StatBadge label="Rescued" value={sample.rescued} color="#86efac" />
|
| 215 |
+
<StatBadge label="Remaining" value={sample.survivors} color="#fcd34d" />
|
| 216 |
+
<StatBadge label="Flood Cells" value={sample.hazards} color="#fca5a5" />
|
| 217 |
+
</div>
|
| 218 |
+
|
| 219 |
+
{/* VARP Scores */}
|
| 220 |
+
<div style={{
|
| 221 |
+
background: "#0f172a",
|
| 222 |
+
border: "1px solid #334155",
|
| 223 |
+
borderRadius: 8,
|
| 224 |
+
padding: "12px 16px",
|
| 225 |
+
}}>
|
| 226 |
+
<div style={{
|
| 227 |
+
display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: 10,
|
| 228 |
+
}}>
|
| 229 |
+
<span style={{ fontSize: 12, fontWeight: 700, color: "#f59e0b", letterSpacing: "0.05em" }}>
|
| 230 |
+
VARP SCORE
|
| 231 |
+
</span>
|
| 232 |
+
<span style={{ fontSize: 20, fontWeight: 800, color: "#22c55e" }}>
|
| 233 |
+
{Math.round(varpComposite * 100)}%
|
| 234 |
+
</span>
|
| 235 |
+
</div>
|
| 236 |
+
<VARPBar label="Spatial" score={varpScores.spatial} color="#3b82f6" />
|
| 237 |
+
<VARPBar label="Temporal" score={varpScores.temporal} color="#22c55e" />
|
| 238 |
+
<VARPBar label="Causal" score={varpScores.causal} color="#ef4444" />
|
| 239 |
+
<VARPBar label="Decision" score={varpScores.decision} color="#f59e0b" />
|
| 240 |
+
</div>
|
| 241 |
+
</div>
|
| 242 |
+
|
| 243 |
+
{/* Right: Reasoning Chains */}
|
| 244 |
+
<div style={{ flex: "1 1 420px", display: "flex", flexDirection: "column", gap: 8 }}>
|
| 245 |
+
<div style={{
|
| 246 |
+
fontSize: 12, fontWeight: 700, color: "#94a3b8",
|
| 247 |
+
letterSpacing: "0.1em", marginBottom: 4,
|
| 248 |
+
}}>
|
| 249 |
+
REASONING CHAIN (4-COMPONENT)
|
| 250 |
+
</div>
|
| 251 |
+
<ChainPanel type="spatial" text={sample.spatial} expanded={expanded.spatial} onToggle={() => toggleChain("spatial")} />
|
| 252 |
+
<ChainPanel type="temporal" text={sample.temporal} expanded={expanded.temporal} onToggle={() => toggleChain("temporal")} />
|
| 253 |
+
<ChainPanel type="causal" text={sample.causal} expanded={expanded.causal} onToggle={() => toggleChain("causal")} />
|
| 254 |
+
<ChainPanel type="decision" text={sample.decision} expanded={expanded.decision} onToggle={() => toggleChain("decision")} />
|
| 255 |
+
|
| 256 |
+
{/* Pipeline Info */}
|
| 257 |
+
<div style={{
|
| 258 |
+
background: "#0f172a",
|
| 259 |
+
border: "1px solid #334155",
|
| 260 |
+
borderRadius: 8,
|
| 261 |
+
padding: "12px 16px",
|
| 262 |
+
marginTop: 4,
|
| 263 |
+
}}>
|
| 264 |
+
<div style={{ fontSize: 11, color: "#94a3b8", marginBottom: 8, letterSpacing: "0.05em" }}>PIPELINE</div>
|
| 265 |
+
<div style={{ display: "flex", alignItems: "center", gap: 6, flexWrap: "wrap" }}>
|
| 266 |
+
{["MAELSTROM Sim", "→", "AEGIS Render", "→", "SFT (12,578)", "→", "GRPO + VARP"].map((item, i) => (
|
| 267 |
+
item === "→" ? (
|
| 268 |
+
<span key={i} style={{ color: "#f59e0b", fontSize: 14 }}>→</span>
|
| 269 |
+
) : (
|
| 270 |
+
<span key={i} style={{
|
| 271 |
+
background: "#1e293b",
|
| 272 |
+
border: "1px solid #475569",
|
| 273 |
+
borderRadius: 4,
|
| 274 |
+
padding: "3px 8px",
|
| 275 |
+
fontSize: 10,
|
| 276 |
+
color: "#e2e8f0",
|
| 277 |
+
}}>
|
| 278 |
+
{item}
|
| 279 |
+
</span>
|
| 280 |
+
)
|
| 281 |
+
))}
|
| 282 |
+
</div>
|
| 283 |
+
<div style={{ fontSize: 10, color: "#64748b", marginTop: 8 }}>
|
| 284 |
+
Base model: nvidia/Cosmos-Reason2-2B · 320 scenarios · 8× H100 on Nebius
|
| 285 |
+
</div>
|
| 286 |
+
</div>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
);
|
| 291 |
+
}
|
aegis-reason/aegis-reason/demo/aegis_scenario_demo.gif
ADDED
|
aegis-reason/aegis-reason/docs/aegis_cookbook_recipe.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Post-Training Cosmos Reason 2 for Disaster Rescue Coordination
|
| 2 |
+
|
| 3 |
+
This recipe demonstrates how to fine-tune **Cosmos Reason 2** for multi-robot disaster rescue reasoning using synthetic simulation data. The approach generates structured 4-component reasoning chains from a physics-informed grid simulation, trains the VLM via SFT, then refines it with GRPO reinforcement learning using a domain-specific reward function.
|
| 4 |
+
|
| 5 |
+
## Overview
|
| 6 |
+
|
| 7 |
+
### End-to-End Workflow
|
| 8 |
+
|
| 9 |
+
```
|
| 10 |
+
Data Generation → SFT Training → GRPO RL → Evaluation
|
| 11 |
+
(MAELSTROM Sim) (cosmos-rl) (cosmos-rl) (VARP Framework)
|
| 12 |
+
```
|
| 13 |
+
|
| 14 |
+
### Key Results
|
| 15 |
+
|
| 16 |
+
| Stage | VARP Score | Notes |
|
| 17 |
+
|-------|-----------|-------|
|
| 18 |
+
| Zero-shot (Cosmos Reason 2) | ~5-15% | No disaster domain knowledge |
|
| 19 |
+
| After SFT (5 epochs) | ~75-85% | Learns structured reasoning format |
|
| 20 |
+
| After GRPO RL | ~85-95% | Refines physical reasoning quality |
|
| 21 |
+
| Oracle (ground truth) | 97.4% | Ceiling from simulation oracle |
|
| 22 |
+
|
| 23 |
+
### What You Will Learn
|
| 24 |
+
|
| 25 |
+
1. How to generate synthetic training data from a physics simulation
|
| 26 |
+
2. How to format image+reasoning pairs for cosmos-rl SFT
|
| 27 |
+
3. How to design a domain-specific reward function for GRPO
|
| 28 |
+
4. How to evaluate physical reasoning with a multi-axis metric
|
| 29 |
+
|
| 30 |
+
## Prerequisites
|
| 31 |
+
|
| 32 |
+
- **Hardware**: 8× H100 80GB GPUs (Nebius Cloud recommended)
|
| 33 |
+
- **Software**: cosmos-reason2 repo, cosmos-rl framework, wandb
|
| 34 |
+
- **Tokens**: HuggingFace token (HF_TOKEN), wandb API key
|
| 35 |
+
- **Time**: ~45 min SFT + ~3 hours GRPO on 8× H100
|
| 36 |
+
|
| 37 |
+
## Step 1: Generate Training Data
|
| 38 |
+
|
| 39 |
+
AEGIS uses the MAELSTROM simulation — a 20×20 grid world with expanding flood zones, 3 rescue robots, and 7 survivors. The simulation runs a complete autonomous rescue pipeline: noisy sensor fusion → Bayesian belief states → fleet coordination → hierarchical A* planning → Q-learning RL.
|
| 40 |
+
|
| 41 |
+
At every simulation step, we capture:
|
| 42 |
+
- **Top-down frame** (640×640 PNG): Global view of the grid showing all entities
|
| 43 |
+
- **Egocentric frame** (640×640 PNG): Per-robot local view within sensor radius
|
| 44 |
+
- **Reasoning chain** (JSON): 4-component ground truth reasoning from simulation oracle
|
| 45 |
+
|
| 46 |
+
### Generate the Dataset
|
| 47 |
+
|
| 48 |
+
```bash
|
| 49 |
+
# Generate 320 scenarios (40 seeds × 4 budgets × 2 intel modes)
|
| 50 |
+
python aegis_data_generator.py --seeds 40 --output aegis_dataset
|
| 51 |
+
```
|
| 52 |
+
|
| 53 |
+
This produces ~12,500 training pairs in ~4 minutes on any CPU. No GPU required for data generation.
|
| 54 |
+
|
| 55 |
+
### Dataset Statistics
|
| 56 |
+
|
| 57 |
+
| Metric | Value |
|
| 58 |
+
|--------|-------|
|
| 59 |
+
| Total SFT records | 12,578 |
|
| 60 |
+
| Unique scenarios | 320 |
|
| 61 |
+
| Top-down frames | 6,289 (95 MB) |
|
| 62 |
+
| Egocentric frames | 6,289 (49 MB) |
|
| 63 |
+
| Reasoning chains | 6,289 (22 MB) |
|
| 64 |
+
| Avg steps per scenario | 48.4 |
|
| 65 |
+
| Mission success rate | 59.7% |
|
| 66 |
+
|
| 67 |
+
### Reasoning Chain Format
|
| 68 |
+
|
| 69 |
+
Each chain has 4 components that teach the model physical reasoning:
|
| 70 |
+
|
| 71 |
+
```
|
| 72 |
+
[SPATIAL GROUNDING] Grid: 20×20. 4 survivors remaining. 241 flood cells.
|
| 73 |
+
Robot 0: position (6,6), sector 6. Robot 1: position (13,5), sector 10.
|
| 74 |
+
Survivor at (1,9), sector 2. Nearest robot: 0 (distance 8)...
|
| 75 |
+
|
| 76 |
+
[TEMPORAL DYNAMICS] Current step: 51. Flood cells: 241. Frontier cells: 20.
|
| 77 |
+
Flood expanding slowly. Predicted flood cells at step 54: ~252...
|
| 78 |
+
|
| 79 |
+
[CAUSAL REASONING] Survivor (1,9): urgency CRITICAL — flood frontier is 1
|
| 80 |
+
cell away. Nearest robot: 0 at distance 8...
|
| 81 |
+
|
| 82 |
+
[DECISION] Recommended: Robot 0 (6,6) → survivor (1,9), sector 2,
|
| 83 |
+
distance 8 steps...
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## Step 2: Convert to LLaVA Format
|
| 87 |
+
|
| 88 |
+
cosmos-rl expects training data in the LLaVA dataset format. Convert our JSONL:
|
| 89 |
+
|
| 90 |
+
```bash
|
| 91 |
+
python aegis_convert_llava.py \
|
| 92 |
+
--input aegis_dataset/sft_data.jsonl \
|
| 93 |
+
--output aegis_llava \
|
| 94 |
+
--views both \
|
| 95 |
+
--val-ratio 0.05
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
This produces:
|
| 99 |
+
- `annotations_train.json` — 11,950 training samples
|
| 100 |
+
- `annotations_val.json` — 628 validation samples
|
| 101 |
+
|
| 102 |
+
Each entry follows the LLaVA structure:
|
| 103 |
+
|
| 104 |
+
```json
|
| 105 |
+
{
|
| 106 |
+
"id": "seed002_b2.0_no_intel_step006_topdown",
|
| 107 |
+
"image": "aegis_dataset/topdown/seed002_b2.0_no_intel_step006.png",
|
| 108 |
+
"conversations": [
|
| 109 |
+
{"from": "human", "value": "<system prompt>\n\n<image>\nAnalyze this disaster..."},
|
| 110 |
+
{"from": "gpt", "value": "[SPATIAL GROUNDING] Grid: 20×20..."}
|
| 111 |
+
]
|
| 112 |
+
}
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## Step 3: SFT Training
|
| 116 |
+
|
| 117 |
+
### Configuration
|
| 118 |
+
|
| 119 |
+
We adapt the standard cosmos-rl SFT recipe for single-frame image inputs (our data is static images, not video):
|
| 120 |
+
|
| 121 |
+
```toml
|
| 122 |
+
# aegis_sft.toml — Key settings
|
| 123 |
+
[custom.dataset]
|
| 124 |
+
annotation_path = "/data/aegis/aegis_llava/annotations_train.json"
|
| 125 |
+
media_path = "/data/aegis/"
|
| 126 |
+
|
| 127 |
+
[custom.vision]
|
| 128 |
+
min_pixels = 3136 # 56×56 minimum
|
| 129 |
+
max_pixels = 409600 # 640×640 matches our frame size
|
| 130 |
+
|
| 131 |
+
[train]
|
| 132 |
+
epoch = 5
|
| 133 |
+
train_batch_per_replica = 16
|
| 134 |
+
optm_lr = 5e-6 # Higher LR for small dataset
|
| 135 |
+
optm_decay_type = "cosine"
|
| 136 |
+
|
| 137 |
+
[policy]
|
| 138 |
+
model_name_or_path = "nvidia/Cosmos-Reason2-2B"
|
| 139 |
+
model_max_length = 4096
|
| 140 |
+
model_gradient_checkpointing = true
|
| 141 |
+
|
| 142 |
+
[policy.parallelism]
|
| 143 |
+
tp_size = 1
|
| 144 |
+
dp_shard_size = 8 # 8-way FSDP across all GPUs
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
### Launch Training
|
| 148 |
+
|
| 149 |
+
```bash
|
| 150 |
+
cd cosmos-reason2/examples/cosmos_rl
|
| 151 |
+
cosmos-rl --config aegis_sft.toml aegis_dataloader.py
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
### Key Design Decisions
|
| 155 |
+
|
| 156 |
+
- **Learning rate 5e-6**: Higher than the Uber recipe (2e-7) because our dataset is ~10× smaller. The higher LR compensates for fewer total gradient steps.
|
| 157 |
+
- **5 epochs**: Small dataset benefits from more passes. Monitor checkpoints for overfitting.
|
| 158 |
+
- **Checkpoints every 50 steps**: Enables multi-checkpoint evaluation to find peak performance (following the Uber recipe finding that peak varies by metric).
|
| 159 |
+
|
| 160 |
+
## Step 4: GRPO Reinforcement Learning
|
| 161 |
+
|
| 162 |
+
After SFT teaches the model the output format and domain vocabulary, GRPO refines the *quality* of physical reasoning using the VARP reward signal.
|
| 163 |
+
|
| 164 |
+
### VARP Reward Function
|
| 165 |
+
|
| 166 |
+
The reward function scores model generations against simulation oracle ground truth across 4 axes:
|
| 167 |
+
|
| 168 |
+
| Component | Weight | What It Measures |
|
| 169 |
+
|-----------|--------|-----------------|
|
| 170 |
+
| Spatial | 30% | Entity identification + position accuracy |
|
| 171 |
+
| Temporal | 20% | Flood count accuracy + expansion awareness |
|
| 172 |
+
| Causal | 25% | Per-survivor urgency classification |
|
| 173 |
+
| Decision | 25% | Robot-survivor assignment optimality |
|
| 174 |
+
|
| 175 |
+
Plus bonus signals:
|
| 176 |
+
- **Format bonus** (+0.1): For using structured `[SECTION]` headers
|
| 177 |
+
- **Completeness bonus** (+0.1): For including all 4 reasoning components
|
| 178 |
+
- **Brevity penalty** (-0.3): For responses under 100 characters
|
| 179 |
+
|
| 180 |
+
Reward range: [-1.0, 1.5]. Validated spread: 1.42 between perfect and vague predictions.
|
| 181 |
+
|
| 182 |
+
### Configuration
|
| 183 |
+
|
| 184 |
+
```toml
|
| 185 |
+
# aegis_grpo.toml — Key settings
|
| 186 |
+
[train.train_policy]
|
| 187 |
+
type = "grpo"
|
| 188 |
+
num_generations = 4 # G=4 completions per prompt
|
| 189 |
+
kl_beta = 0.05 # Crucial for preventing overfitting
|
| 190 |
+
temperature = 0.7 # Sampling temperature for rollouts
|
| 191 |
+
|
| 192 |
+
[policy]
|
| 193 |
+
model_name_or_path = "<sft_checkpoint_path>"
|
| 194 |
+
```
|
| 195 |
+
|
| 196 |
+
### Launch RL Training
|
| 197 |
+
|
| 198 |
+
```bash
|
| 199 |
+
cosmos-rl --config aegis_grpo.toml aegis_grpo_reward.py
|
| 200 |
+
```
|
| 201 |
+
|
| 202 |
+
### Why KL Beta Matters
|
| 203 |
+
|
| 204 |
+
Following the Physical Plausibility Prediction recipe from the Cosmos Cookbook, we set `kl_beta = 0.05` (positive) rather than the common practice of `kl_beta = 0`. In our experiments, without KL regularization, the model overfits to the format bonus and generates templated responses that score well on structure but poorly on spatial accuracy. The KL term keeps the model close to the SFT checkpoint while improving reasoning quality.
|
| 205 |
+
|
| 206 |
+
## Step 5: Evaluation
|
| 207 |
+
|
| 208 |
+
### VARP Framework
|
| 209 |
+
|
| 210 |
+
Evaluate the fine-tuned model using the VARP (Visual-Action Reasoning Precision) framework:
|
| 211 |
+
|
| 212 |
+
```bash
|
| 213 |
+
# Run inference on validation frames
|
| 214 |
+
python aegis_inference.py \
|
| 215 |
+
--checkpoint <grpo_checkpoint> \
|
| 216 |
+
--image-dir aegis_dataset/topdown/ \
|
| 217 |
+
--max-images 100 \
|
| 218 |
+
--evaluate \
|
| 219 |
+
--output inference_results.json
|
| 220 |
+
|
| 221 |
+
# Score against ground truth
|
| 222 |
+
python aegis_varp.py \
|
| 223 |
+
--predictions inference_results.json \
|
| 224 |
+
--ground-truth aegis_dataset/chains/ \
|
| 225 |
+
--output varp_report.json
|
| 226 |
+
```
|
| 227 |
+
|
| 228 |
+
### Multi-Checkpoint Evaluation
|
| 229 |
+
|
| 230 |
+
Following the Uber recipe, evaluate multiple checkpoints to find peak performance:
|
| 231 |
+
|
| 232 |
+
```bash
|
| 233 |
+
for step in 50 100 150 200 250; do
|
| 234 |
+
python aegis_inference.py \
|
| 235 |
+
--checkpoint outputs/aegis_grpo/checkpoints/step_${step}/policy \
|
| 236 |
+
--image-dir aegis_dataset/topdown/ \
|
| 237 |
+
--max-images 100 \
|
| 238 |
+
--output results_step${step}.json
|
| 239 |
+
|
| 240 |
+
python aegis_varp.py \
|
| 241 |
+
--predictions results_step${step}.json \
|
| 242 |
+
--ground-truth aegis_dataset/chains/ \
|
| 243 |
+
--output varp_step${step}.json
|
| 244 |
+
done
|
| 245 |
+
```
|
| 246 |
+
|
| 247 |
+
## Step 6: Deployment
|
| 248 |
+
|
| 249 |
+
### Quantize to FP8
|
| 250 |
+
|
| 251 |
+
For inference deployment, quantize the VLM to FP8:
|
| 252 |
+
|
| 253 |
+
```bash
|
| 254 |
+
# Using the cosmos-reason2 quantization script
|
| 255 |
+
python quantize_fp8.py \
|
| 256 |
+
--model-path <best_checkpoint> \
|
| 257 |
+
--output-path aegis_reason_fp8
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
### Serve with vLLM
|
| 261 |
+
|
| 262 |
+
```bash
|
| 263 |
+
vllm serve <best_checkpoint> \
|
| 264 |
+
--allowed-local-media-path "$(pwd)" \
|
| 265 |
+
--max-model-len 4096 \
|
| 266 |
+
--reasoning-parser qwen3 \
|
| 267 |
+
--port 8000
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
## Conclusion
|
| 271 |
+
|
| 272 |
+
This recipe demonstrates that physics-grounded synthetic data can effectively teach VLMs domain-specific physical reasoning. Key insights:
|
| 273 |
+
|
| 274 |
+
1. **Synthetic data quality matters more than quantity**: Our 12,578 samples from a physics simulation outperform what random data collection would achieve, because every sample has precise ground truth reasoning.
|
| 275 |
+
|
| 276 |
+
2. **Structured reasoning chains transfer**: The 4-component format (spatial → temporal → causal → decision) teaches the model a complete physical reasoning pipeline, not just pattern matching.
|
| 277 |
+
|
| 278 |
+
3. **GRPO with domain rewards adds measurable value**: The VARP reward function provides a deterministic, simulation-grounded signal that avoids the noise of human preference data.
|
| 279 |
+
|
| 280 |
+
4. **The approach generalizes**: While AEGIS demonstrates on disaster rescue, the same pipeline (simulation → rendering → structured chains → SFT → GRPO) applies to any domain with a simulatable environment.
|
| 281 |
+
|
| 282 |
+
## Citation
|
| 283 |
+
|
| 284 |
+
```bibtex
|
| 285 |
+
@misc{aegis_reason_2026,
|
| 286 |
+
title={AEGIS-Reason: Post-Training Cosmos Reason 2 for Disaster Rescue Coordination},
|
| 287 |
+
year={2026},
|
| 288 |
+
month={February},
|
| 289 |
+
howpublished={\url{https://nvidia-cosmos.github.io/cosmos-cookbook/}},
|
| 290 |
+
note={NVIDIA Cosmos Cookoff Submission}
|
| 291 |
+
}
|
| 292 |
+
```
|
| 293 |
+
|
| 294 |
+
## References
|
| 295 |
+
|
| 296 |
+
- NVIDIA Cosmos Reason 2: Physical AI Common Sense and Embodied Reasoning
|
| 297 |
+
- Cosmos Cookbook: Post-Training Guide for Cosmos Reason
|
| 298 |
+
- Uber/NVIDIA: Post-train Cosmos Reason 2 for AV Video Captioning and VQA
|
| 299 |
+
- Physical Plausibility Prediction with Cosmos Reason 1 (GRPO recipe)
|
| 300 |
+
- DeepSeekMath: Group Relative Policy Optimization (GRPO)
|
aegis-reason/aegis-reason/docs/benchmark_analysis.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"total_chains": 6289,
|
| 3 |
+
"conditions": {
|
| 4 |
+
"b0.3_no_intel": {
|
| 5 |
+
"count": 1165,
|
| 6 |
+
"avg_step": 34.67982832618026,
|
| 7 |
+
"avg_hazards": 179.05321888412018,
|
| 8 |
+
"avg_chain_len": 1788.1699570815451,
|
| 9 |
+
"pct_critical": 94.2489270386266
|
| 10 |
+
},
|
| 11 |
+
"b0.3_with_intel": {
|
| 12 |
+
"count": 1173,
|
| 13 |
+
"avg_step": 34.81670929241262,
|
| 14 |
+
"avg_hazards": 179.20630861040067,
|
| 15 |
+
"avg_chain_len": 1786.1338448422848,
|
| 16 |
+
"pct_critical": 94.20289855072464
|
| 17 |
+
},
|
| 18 |
+
"b1.0_no_intel": {
|
| 19 |
+
"count": 747,
|
| 20 |
+
"avg_step": 25.22222222222222,
|
| 21 |
+
"avg_hazards": 127.31593038821954,
|
| 22 |
+
"avg_chain_len": 1631.9598393574297,
|
| 23 |
+
"pct_critical": 87.68406961178046
|
| 24 |
+
},
|
| 25 |
+
"b1.0_with_intel": {
|
| 26 |
+
"count": 806,
|
| 27 |
+
"avg_step": 27.52605459057072,
|
| 28 |
+
"avg_hazards": 141.04590570719603,
|
| 29 |
+
"avg_chain_len": 1617.5062034739453,
|
| 30 |
+
"pct_critical": 88.21339950372209
|
| 31 |
+
},
|
| 32 |
+
"b2.0_no_intel": {
|
| 33 |
+
"count": 506,
|
| 34 |
+
"avg_step": 13.318181818181818,
|
| 35 |
+
"avg_hazards": 62.73122529644269,
|
| 36 |
+
"avg_chain_len": 1666.1837944664032,
|
| 37 |
+
"pct_critical": 81.02766798418972
|
| 38 |
+
},
|
| 39 |
+
"b2.0_with_intel": {
|
| 40 |
+
"count": 693,
|
| 41 |
+
"avg_step": 23.867243867243868,
|
| 42 |
+
"avg_hazards": 120.80086580086581,
|
| 43 |
+
"avg_chain_len": 1642.7041847041846,
|
| 44 |
+
"pct_critical": 87.73448773448773
|
| 45 |
+
},
|
| 46 |
+
"b3.0_no_intel": {
|
| 47 |
+
"count": 506,
|
| 48 |
+
"avg_step": 13.318181818181818,
|
| 49 |
+
"avg_hazards": 62.73122529644269,
|
| 50 |
+
"avg_chain_len": 1666.1837944664032,
|
| 51 |
+
"pct_critical": 81.02766798418972
|
| 52 |
+
},
|
| 53 |
+
"b3.0_with_intel": {
|
| 54 |
+
"count": 693,
|
| 55 |
+
"avg_step": 23.867243867243868,
|
| 56 |
+
"avg_hazards": 120.80086580086581,
|
| 57 |
+
"avg_chain_len": 1642.7041847041846,
|
| 58 |
+
"pct_critical": 87.73448773448773
|
| 59 |
+
}
|
| 60 |
+
},
|
| 61 |
+
"difficulty_tiers": {
|
| 62 |
+
"easy": 560,
|
| 63 |
+
"medium": 555,
|
| 64 |
+
"hard": 1222
|
| 65 |
+
},
|
| 66 |
+
"avg_chain_length": 1695.6754650977898,
|
| 67 |
+
"max_chain_length": 2054,
|
| 68 |
+
"min_chain_length": 1186
|
| 69 |
+
}
|
aegis-reason/aegis-reason/docs/hf_dataset_card.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
license: cc-by-4.0
|
| 5 |
+
task_categories:
|
| 6 |
+
- visual-question-answering
|
| 7 |
+
- image-to-text
|
| 8 |
+
tags:
|
| 9 |
+
- physical-ai
|
| 10 |
+
- disaster-rescue
|
| 11 |
+
- multi-agent
|
| 12 |
+
- cosmos-reason
|
| 13 |
+
- spatial-reasoning
|
| 14 |
+
- chain-of-thought
|
| 15 |
+
- robotics
|
| 16 |
+
- cosmos-cookoff
|
| 17 |
+
size_categories:
|
| 18 |
+
- 10K<n<100K
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# AEGIS Disaster Rescue Reasoning Dataset
|
| 22 |
+
|
| 23 |
+
A synthetic dataset of **12,578 (image, reasoning chain)** pairs for training vision-language models on multi-robot disaster rescue coordination. Generated from the MAELSTROM physics simulation for the [NVIDIA Cosmos Cookoff](https://luma.com/nvidia-cosmos-cookoff).
|
| 24 |
+
|
| 25 |
+
## Dataset Description
|
| 26 |
+
|
| 27 |
+
Each sample contains:
|
| 28 |
+
- **Top-down frame** (640×640 PNG): Bird's-eye view of a 20×20 grid with robots (colored triangles), survivors (green dots), flood zones (blue), sector grid, and assignment lines
|
| 29 |
+
- **Egocentric frame** (640×640 PNG): Robot-POV with local sensor view and fog-of-war
|
| 30 |
+
- **4-component reasoning chain**: Structured ground truth from simulation oracle
|
| 31 |
+
|
| 32 |
+
### Reasoning Chain Format
|
| 33 |
+
|
| 34 |
+
```
|
| 35 |
+
[SPATIAL GROUNDING] Grid: 20×20. 4 survivors remaining. 18 flood cells.
|
| 36 |
+
Robot 0: position (12,11), sector 11. Robot 1: position (10,4), sector 9...
|
| 37 |
+
|
| 38 |
+
[TEMPORAL DYNAMICS] Current step: 4. Flood cells: 18. Frontier cells: 18.
|
| 39 |
+
Predicted flood cells at step 7: ~22...
|
| 40 |
+
|
| 41 |
+
[CAUSAL REASONING] Survivor (1,15): urgency CRITICAL — flood frontier
|
| 42 |
+
is 2 cells away. Nearest robot: 0 at distance 15...
|
| 43 |
+
|
| 44 |
+
[DECISION] Recommended: Robot 0 (12,11) → survivor (13,11), sector 11,
|
| 45 |
+
distance 1 steps...
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
## Dataset Statistics
|
| 49 |
+
|
| 50 |
+
| Metric | Value |
|
| 51 |
+
|--------|-------|
|
| 52 |
+
| Total SFT records | 12,578 |
|
| 53 |
+
| Unique scenarios | 320 |
|
| 54 |
+
| Top-down frames | 6,289 |
|
| 55 |
+
| Egocentric frames | 6,289 |
|
| 56 |
+
| Reasoning chains | 6,289 |
|
| 57 |
+
| Random seeds | 40 |
|
| 58 |
+
| Thinking budgets | 4 (0.3, 1.0, 2.0, 3.0) |
|
| 59 |
+
| Intel modes | 2 (with/without sector pre-intelligence) |
|
| 60 |
+
| Mission success rate | 59.7% |
|
| 61 |
+
| Avg steps per scenario | 48.4 |
|
| 62 |
+
|
| 63 |
+
## Scenario Diversity
|
| 64 |
+
|
| 65 |
+
- **Thinking budgets** control scan radius and planner sophistication (reactive → strategic)
|
| 66 |
+
- **Intel modes** simulate with/without pre-loaded sector intelligence (Nemotron ON/OFF)
|
| 67 |
+
- **40 random seeds** create unique terrain layouts, flood patterns, and entity placements
|
| 68 |
+
- Flood dynamics use cellular automaton with probabilistic expansion
|
| 69 |
+
|
| 70 |
+
## Simulation Engine
|
| 71 |
+
|
| 72 |
+
Data generated from MAELSTROM — a physics-informed grid simulation with:
|
| 73 |
+
- **Hydrodynamic flood model**: Cellular automaton with configurable expansion probability
|
| 74 |
+
- **Noisy sensor fusion**: 5% noise rate on observations
|
| 75 |
+
- **Bayesian belief states**: Per-robot belief grids updated via likelihood fusion
|
| 76 |
+
- **Fleet coordination**: Greedy assignment with priority sector discounting
|
| 77 |
+
- **Hierarchical planning**: A* (full/depth-limited), potential fields, Q-learning RL
|
| 78 |
+
- **16-sector grid**: 4×4 sector decomposition for strategic reasoning
|
| 79 |
+
|
| 80 |
+
## Intended Use
|
| 81 |
+
|
| 82 |
+
### Primary: Fine-tuning Cosmos Reason 2
|
| 83 |
+
|
| 84 |
+
The dataset is in LLaVA format for direct use with the `cosmos-rl` framework:
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
# Convert to LLaVA format
|
| 88 |
+
python aegis_convert_llava.py --input sft_data.jsonl --output llava/
|
| 89 |
+
|
| 90 |
+
# Train with cosmos-rl
|
| 91 |
+
cosmos-rl --config aegis_sft.toml aegis_dataloader.py
|
| 92 |
+
```
|
| 93 |
+
|
| 94 |
+
### Secondary Applications
|
| 95 |
+
|
| 96 |
+
- Benchmarking VLM spatial reasoning capabilities
|
| 97 |
+
- Evaluating physical AI reasoning quality (VARP metric)
|
| 98 |
+
- Studying multi-agent coordination reasoning
|
| 99 |
+
- Training smaller student models via distillation
|
| 100 |
+
|
| 101 |
+
## Evaluation
|
| 102 |
+
|
| 103 |
+
Use the VARP (Visual-Action Reasoning Precision) framework for evaluation:
|
| 104 |
+
|
| 105 |
+
| Prediction Quality | VARP Score |
|
| 106 |
+
|---|---|
|
| 107 |
+
| Oracle (ground truth) | 97.4% ± 3.3% |
|
| 108 |
+
| Partial (some correct) | ~41% |
|
| 109 |
+
| Vague/generic | ~5% |
|
| 110 |
+
|
| 111 |
+
VARP axes: Spatial (30%), Temporal (20%), Causal (25%), Decision (25%)
|
| 112 |
+
|
| 113 |
+
## Limitations
|
| 114 |
+
|
| 115 |
+
- Grid-world abstraction (not photorealistic scenes)
|
| 116 |
+
- Fixed 20×20 grid size, 3 robots, 7 survivors
|
| 117 |
+
- 2D navigation only (no 3D or continuous control)
|
| 118 |
+
- Flood expansion is stochastic but simplified (no terrain, drainage, wind)
|
| 119 |
+
- Reasoning chains generated algorithmically (no human annotation)
|
| 120 |
+
|
| 121 |
+
## Data Generation
|
| 122 |
+
|
| 123 |
+
Fully reproducible from source code:
|
| 124 |
+
|
| 125 |
+
```bash
|
| 126 |
+
python aegis_data_generator.py --seeds 40 --output aegis_dataset
|
| 127 |
+
# Generates in ~4 minutes on any CPU, no GPU required
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## Citation
|
| 131 |
+
|
| 132 |
+
```bibtex
|
| 133 |
+
@misc{aegis_dataset_2026,
|
| 134 |
+
title={AEGIS Disaster Rescue Reasoning Dataset},
|
| 135 |
+
year={2026},
|
| 136 |
+
howpublished={\url{https://huggingface.co/datasets/aegis-reason/disaster-rescue}},
|
| 137 |
+
note={NVIDIA Cosmos Cookoff 2026}
|
| 138 |
+
}
|
| 139 |
+
```
|
| 140 |
+
|
| 141 |
+
## License
|
| 142 |
+
|
| 143 |
+
CC BY 4.0 — Free for research and commercial use with attribution.
|
aegis-reason/aegis-reason/maelstrom_core.py
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MAELSTROM Simulation Core — Headless Engine for AEGIS Data Generation
|
| 3 |
+
======================================================================
|
| 4 |
+
Extracted from Project_MAELSTROM.ipynb. Stripped of all Gradio UI,
|
| 5 |
+
NVIDIA API calls, matplotlib rendering, and interactive components.
|
| 6 |
+
|
| 7 |
+
This is the pure simulation engine: grid world, flood dynamics,
|
| 8 |
+
Bayesian belief, multi-agent coordination, hierarchical planning,
|
| 9 |
+
Q-learning RL, and the sense-think-act agent loop.
|
| 10 |
+
|
| 11 |
+
Used by aegis_data_generator.py to run thousands of deterministic
|
| 12 |
+
simulations and capture (frame, reasoning_chain) pairs at every step.
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
import random
|
| 17 |
+
import heapq
|
| 18 |
+
from collections import deque
|
| 19 |
+
from typing import Dict, Tuple, List, Optional, Set
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
# ============================================================
|
| 23 |
+
# CONFIGURATION
|
| 24 |
+
# ============================================================
|
| 25 |
+
class SimConfig:
|
| 26 |
+
GRID_SIZE: int = 20
|
| 27 |
+
NUM_AGENTS: int = 3
|
| 28 |
+
NUM_SURVIVORS: int = 7
|
| 29 |
+
NUM_HAZARDS: int = 5
|
| 30 |
+
RESCUE_TARGET: int = 5
|
| 31 |
+
MAX_STEPS: int = 100
|
| 32 |
+
THINKING_BUDGET: float = 2.0
|
| 33 |
+
FLOOD_PROB_BASE: float = 0.08
|
| 34 |
+
NOISE_LEVEL: float = 0.05
|
| 35 |
+
SENSOR_RADIUS: int = 5
|
| 36 |
+
LEARNING_RATE: float = 0.1
|
| 37 |
+
DISCOUNT_FACTOR: float = 0.95
|
| 38 |
+
EPSILON: float = 0.03
|
| 39 |
+
REPLAY_BUFFER_SIZE: int = 1000
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# ============================================================
|
| 43 |
+
# SECTOR MAP — 20×20 grid → 16 sectors (4×4, each 5×5)
|
| 44 |
+
# ============================================================
|
| 45 |
+
# 1 2 3 4 (rows 0–4)
|
| 46 |
+
# 5 6 7 8 (rows 5–9)
|
| 47 |
+
# 9 10 11 12 (rows 10–14)
|
| 48 |
+
# 13 14 15 16 (rows 15–19)
|
| 49 |
+
|
| 50 |
+
SECTOR_GRID = {}
|
| 51 |
+
for _sec in range(1, 17):
|
| 52 |
+
_rb = (_sec - 1) // 4
|
| 53 |
+
_cb = (_sec - 1) % 4
|
| 54 |
+
SECTOR_GRID[_sec] = (_rb * 5, _rb * 5 + 5, _cb * 5, _cb * 5 + 5)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def get_sector_for_cell(r: int, c: int) -> int:
|
| 58 |
+
return min(r // 5, 3) * 4 + min(c // 5, 3) + 1
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def get_sector_center(sector_num: int) -> Tuple[int, int]:
|
| 62 |
+
if sector_num not in SECTOR_GRID:
|
| 63 |
+
return (10, 10)
|
| 64 |
+
r_start, r_end, c_start, c_end = SECTOR_GRID[sector_num]
|
| 65 |
+
return ((r_start + r_end) // 2, (c_start + c_end) // 2)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def get_scan_radius(budget: float) -> int:
|
| 69 |
+
if budget >= 2.0: return 7
|
| 70 |
+
elif budget >= 1.0: return 5
|
| 71 |
+
elif budget >= 0.5: return 3
|
| 72 |
+
else: return 2
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
# ============================================================
|
| 76 |
+
# WORLD MODEL — Physics-informed flood dynamics
|
| 77 |
+
# ============================================================
|
| 78 |
+
class HydroDynamicWorld:
|
| 79 |
+
EMPTY: int = 0
|
| 80 |
+
HAZARD: int = 1
|
| 81 |
+
SURVIVOR: int = 2
|
| 82 |
+
|
| 83 |
+
def __init__(self, flood_intensity: float = 1.0):
|
| 84 |
+
self.grid_size = SimConfig.GRID_SIZE
|
| 85 |
+
self.num_agents = SimConfig.NUM_AGENTS
|
| 86 |
+
self.flood_prob = SimConfig.FLOOD_PROB_BASE * flood_intensity
|
| 87 |
+
self.flood_rng = None
|
| 88 |
+
self.grid = None
|
| 89 |
+
self.agent_positions = {}
|
| 90 |
+
self.survivors_rescued = 0
|
| 91 |
+
|
| 92 |
+
def reset(self) -> Dict:
|
| 93 |
+
self.grid = np.zeros((self.grid_size, self.grid_size), dtype=int)
|
| 94 |
+
self.agent_positions = {}
|
| 95 |
+
self.survivors_rescued = 0
|
| 96 |
+
|
| 97 |
+
for _ in range(SimConfig.NUM_HAZARDS):
|
| 98 |
+
rx, ry = np.random.randint(0, self.grid_size, 2)
|
| 99 |
+
self.grid[rx, ry] = self.HAZARD
|
| 100 |
+
|
| 101 |
+
for _ in range(SimConfig.NUM_SURVIVORS):
|
| 102 |
+
for _ in range(100):
|
| 103 |
+
rx, ry = np.random.randint(0, self.grid_size, 2)
|
| 104 |
+
if self.grid[rx, ry] == self.EMPTY:
|
| 105 |
+
self.grid[rx, ry] = self.SURVIVOR
|
| 106 |
+
break
|
| 107 |
+
|
| 108 |
+
for i in range(self.num_agents):
|
| 109 |
+
for _ in range(100):
|
| 110 |
+
rx, ry = np.random.randint(0, self.grid_size, 2)
|
| 111 |
+
if self.grid[rx, ry] == self.EMPTY:
|
| 112 |
+
self.agent_positions[i] = (rx, ry)
|
| 113 |
+
break
|
| 114 |
+
|
| 115 |
+
return self._get_state()
|
| 116 |
+
|
| 117 |
+
def _simulate_flood_dynamics(self) -> None:
|
| 118 |
+
new_grid = self.grid.copy()
|
| 119 |
+
rows, cols = self.grid.shape
|
| 120 |
+
flood_indices = np.argwhere(self.grid == self.HAZARD)
|
| 121 |
+
rng = self.flood_rng if self.flood_rng else np.random
|
| 122 |
+
for r, c in flood_indices:
|
| 123 |
+
for nr, nc in [(r-1,c), (r+1,c), (r,c-1), (r,c+1)]:
|
| 124 |
+
if 0 <= nr < rows and 0 <= nc < cols and self.grid[nr, nc] == self.EMPTY:
|
| 125 |
+
if rng.random() < self.flood_prob:
|
| 126 |
+
new_grid[nr, nc] = self.HAZARD
|
| 127 |
+
self.grid = new_grid
|
| 128 |
+
|
| 129 |
+
def step(self, actions: Dict[int, int]) -> Tuple[Dict, Dict[int, float], bool]:
|
| 130 |
+
self._simulate_flood_dynamics()
|
| 131 |
+
rewards = {}
|
| 132 |
+
for agent_id, action in actions.items():
|
| 133 |
+
x, y = self.agent_positions[agent_id]
|
| 134 |
+
if action == 1: x = max(0, x - 1)
|
| 135 |
+
elif action == 2: x = min(self.grid_size - 1, x + 1)
|
| 136 |
+
elif action == 3: y = max(0, y - 1)
|
| 137 |
+
elif action == 4: y = min(self.grid_size - 1, y + 1)
|
| 138 |
+
self.agent_positions[agent_id] = (x, y)
|
| 139 |
+
reward = -0.1
|
| 140 |
+
cell = self.grid[x, y]
|
| 141 |
+
if cell == self.SURVIVOR:
|
| 142 |
+
reward += 10.0
|
| 143 |
+
self.grid[x, y] = self.EMPTY
|
| 144 |
+
self.survivors_rescued += 1
|
| 145 |
+
elif cell == self.HAZARD:
|
| 146 |
+
reward -= 5.0
|
| 147 |
+
rewards[agent_id] = reward
|
| 148 |
+
return self._get_state(), rewards, self.survivors_rescued >= SimConfig.RESCUE_TARGET
|
| 149 |
+
|
| 150 |
+
def _get_state(self) -> Dict:
|
| 151 |
+
return {
|
| 152 |
+
'grid': self.grid.copy(),
|
| 153 |
+
'agents': self.agent_positions.copy(),
|
| 154 |
+
'rescued': self.survivors_rescued,
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
# ============================================================
|
| 159 |
+
# PERCEPTION — Noisy sensor array
|
| 160 |
+
# ============================================================
|
| 161 |
+
class SensorFusion:
|
| 162 |
+
def __init__(self, noise_level: float = SimConfig.NOISE_LEVEL):
|
| 163 |
+
self.noise_level = noise_level
|
| 164 |
+
|
| 165 |
+
def scan(self, ground_truth_grid: np.ndarray, agent_pos: Tuple[int, int],
|
| 166 |
+
radius: int = None) -> Dict[Tuple[int, int], int]:
|
| 167 |
+
if radius is None:
|
| 168 |
+
radius = SimConfig.SENSOR_RADIUS
|
| 169 |
+
rows, cols = ground_truth_grid.shape
|
| 170 |
+
x, y = agent_pos
|
| 171 |
+
observations = {}
|
| 172 |
+
for r in range(max(0, x - radius), min(rows, x + radius + 1)):
|
| 173 |
+
for c in range(max(0, y - radius), min(cols, y + radius + 1)):
|
| 174 |
+
if abs(x - r) + abs(y - c) <= radius:
|
| 175 |
+
true_val = ground_truth_grid[r, c]
|
| 176 |
+
observed_val = true_val
|
| 177 |
+
if np.random.random() < self.noise_level:
|
| 178 |
+
if true_val == 0:
|
| 179 |
+
observed_val = 1 if np.random.random() < 0.7 else 2
|
| 180 |
+
elif true_val == 1:
|
| 181 |
+
observed_val = 0 if np.random.random() < 0.6 else 2
|
| 182 |
+
else:
|
| 183 |
+
observed_val = 0 if np.random.random() < 0.8 else 1
|
| 184 |
+
observations[(r, c)] = observed_val
|
| 185 |
+
return observations
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# ============================================================
|
| 189 |
+
# BAYESIAN BELIEF STATE — Cosmos-style world model
|
| 190 |
+
# ============================================================
|
| 191 |
+
class BayesianBeliefState:
|
| 192 |
+
def __init__(self, grid_size: int):
|
| 193 |
+
self.grid_size = grid_size
|
| 194 |
+
self.belief_grid = np.full((grid_size, grid_size, 3), 1.0 / 3.0, dtype=float)
|
| 195 |
+
|
| 196 |
+
def update(self, observations: Dict[Tuple[int, int], int]) -> None:
|
| 197 |
+
for (r, c), obs_val in observations.items():
|
| 198 |
+
likelihood = np.zeros(3)
|
| 199 |
+
likelihood[obs_val] = 0.85
|
| 200 |
+
likelihood[likelihood == 0] = 0.075
|
| 201 |
+
prior = self.belief_grid[r, c]
|
| 202 |
+
posterior = likelihood * prior
|
| 203 |
+
posterior /= posterior.sum()
|
| 204 |
+
self.belief_grid[r, c] = posterior
|
| 205 |
+
|
| 206 |
+
def inject_intel(self, observations: Dict[Tuple[int, int], int]) -> None:
|
| 207 |
+
for (r, c), obs_val in observations.items():
|
| 208 |
+
belief = np.array([0.01, 0.01, 0.01])
|
| 209 |
+
belief[obs_val] = 0.98
|
| 210 |
+
self.belief_grid[r, c] = belief
|
| 211 |
+
|
| 212 |
+
def get_planning_grid(self) -> np.ndarray:
|
| 213 |
+
return self.belief_grid.argmax(axis=2)
|
| 214 |
+
|
| 215 |
+
def get_scanned_mask(self) -> np.ndarray:
|
| 216 |
+
uniform = np.full(3, 1.0 / 3.0)
|
| 217 |
+
return ~np.all(np.isclose(self.belief_grid, uniform, atol=0.01), axis=2)
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
# ============================================================
|
| 221 |
+
# FLEET COORDINATOR — Multi-agent task allocation
|
| 222 |
+
# ============================================================
|
| 223 |
+
class FleetCoordinator:
|
| 224 |
+
def __init__(self):
|
| 225 |
+
self.assignments: Dict[int, Optional[Tuple[int, int]]] = {}
|
| 226 |
+
self.priority_sectors: List[int] = []
|
| 227 |
+
|
| 228 |
+
def set_priority_sectors(self, sectors: List[int]):
|
| 229 |
+
self.priority_sectors = sectors
|
| 230 |
+
|
| 231 |
+
def allocate_targets(self, agent_positions: Dict[int, Tuple[int, int]],
|
| 232 |
+
grid: np.ndarray) -> Dict[int, Optional[Tuple[int, int]]]:
|
| 233 |
+
survivors = list(zip(*np.where(grid == 2)))
|
| 234 |
+
if not survivors:
|
| 235 |
+
return self._assign_exploration_targets(agent_positions, grid)
|
| 236 |
+
|
| 237 |
+
self.assignments = {}
|
| 238 |
+
assigned_agents = set()
|
| 239 |
+
assigned_survivors = set()
|
| 240 |
+
|
| 241 |
+
PRIORITY_DISCOUNT = 3
|
| 242 |
+
pairs = []
|
| 243 |
+
for aid, pos in agent_positions.items():
|
| 244 |
+
for s in survivors:
|
| 245 |
+
dist = abs(pos[0] - s[0]) + abs(pos[1] - s[1])
|
| 246 |
+
if self.priority_sectors and get_sector_for_cell(s[0], s[1]) in self.priority_sectors:
|
| 247 |
+
dist = max(0, dist - PRIORITY_DISCOUNT)
|
| 248 |
+
pairs.append((dist, aid, s))
|
| 249 |
+
pairs.sort()
|
| 250 |
+
for dist, aid, surv in pairs:
|
| 251 |
+
if aid in assigned_agents or surv in assigned_survivors:
|
| 252 |
+
continue
|
| 253 |
+
self.assignments[aid] = surv
|
| 254 |
+
assigned_agents.add(aid)
|
| 255 |
+
assigned_survivors.add(surv)
|
| 256 |
+
|
| 257 |
+
for aid in agent_positions:
|
| 258 |
+
if aid not in self.assignments:
|
| 259 |
+
self.assignments[aid] = self._pick_exploration_target(
|
| 260 |
+
agent_positions[aid], agent_positions, grid)
|
| 261 |
+
|
| 262 |
+
return self.assignments
|
| 263 |
+
|
| 264 |
+
def _assign_exploration_targets(self, agent_positions, grid):
|
| 265 |
+
size = grid.shape[0]
|
| 266 |
+
if self.priority_sectors:
|
| 267 |
+
assignments = {}
|
| 268 |
+
for i, aid in enumerate(agent_positions.keys()):
|
| 269 |
+
sec = self.priority_sectors[i % len(self.priority_sectors)]
|
| 270 |
+
assignments[aid] = get_sector_center(sec)
|
| 271 |
+
return assignments
|
| 272 |
+
|
| 273 |
+
quadrant_centers = [
|
| 274 |
+
(size // 4, size // 4), (size // 4, 3 * size // 4),
|
| 275 |
+
(3 * size // 4, size // 4), (3 * size // 4, 3 * size // 4),
|
| 276 |
+
(size // 2, size // 2)]
|
| 277 |
+
assignments = {}
|
| 278 |
+
used = set()
|
| 279 |
+
for aid, pos in agent_positions.items():
|
| 280 |
+
best = None
|
| 281 |
+
best_dist = float('inf')
|
| 282 |
+
for q in quadrant_centers:
|
| 283 |
+
if q not in used:
|
| 284 |
+
d = abs(pos[0] - q[0]) + abs(pos[1] - q[1])
|
| 285 |
+
if d < best_dist:
|
| 286 |
+
best_dist = d
|
| 287 |
+
best = q
|
| 288 |
+
if best:
|
| 289 |
+
used.add(best)
|
| 290 |
+
assignments[aid] = best if best else (random.randint(0, size - 1), random.randint(0, size - 1))
|
| 291 |
+
return assignments
|
| 292 |
+
|
| 293 |
+
def _pick_exploration_target(self, my_pos, all_positions, grid):
|
| 294 |
+
size = grid.shape[0]
|
| 295 |
+
best_pos, best_score = None, -float('inf')
|
| 296 |
+
for _ in range(20):
|
| 297 |
+
r, c = random.randint(0, size - 1), random.randint(0, size - 1)
|
| 298 |
+
if grid[r, c] == 1:
|
| 299 |
+
continue
|
| 300 |
+
min_dist = min(abs(r - p[0]) + abs(c - p[1]) for p in all_positions.values())
|
| 301 |
+
if min_dist > best_score:
|
| 302 |
+
best_score = min_dist
|
| 303 |
+
best_pos = (r, c)
|
| 304 |
+
return best_pos if best_pos else (size // 2, size // 2)
|
| 305 |
+
|
| 306 |
+
|
| 307 |
+
# ============================================================
|
| 308 |
+
# MOTION CONTROLLER
|
| 309 |
+
# ============================================================
|
| 310 |
+
class ProtoMotions:
|
| 311 |
+
ACTION_MAP = {"STAY": 0, "MOVE_UP": 1, "MOVE_DOWN": 2, "MOVE_LEFT": 3, "MOVE_RIGHT": 4}
|
| 312 |
+
REVERSE_MAP = {0: "STAY", 1: "MOVE_UP", 2: "MOVE_DOWN", 3: "MOVE_LEFT", 4: "MOVE_RIGHT"}
|
| 313 |
+
|
| 314 |
+
def translate_intent(self, intent: str) -> int:
|
| 315 |
+
return self.ACTION_MAP.get(intent, 0)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
# ============================================================
|
| 319 |
+
# HIERARCHICAL PLANNER — Jetson Edge-to-Cloud
|
| 320 |
+
# ============================================================
|
| 321 |
+
class HierarchicalPlanner:
|
| 322 |
+
def _heuristic(self, a, b):
|
| 323 |
+
return abs(a[0] - b[0]) + abs(a[1] - b[1])
|
| 324 |
+
|
| 325 |
+
def _get_neighbors(self, pos, grid):
|
| 326 |
+
rows, cols = grid.shape
|
| 327 |
+
x, y = pos
|
| 328 |
+
moves = [("MOVE_UP", (x - 1, y)), ("MOVE_DOWN", (x + 1, y)),
|
| 329 |
+
("MOVE_LEFT", (x, y - 1)), ("MOVE_RIGHT", (x, y + 1))]
|
| 330 |
+
return [(d, (nx, ny)) for d, (nx, ny) in moves if 0 <= nx < rows and 0 <= ny < cols]
|
| 331 |
+
|
| 332 |
+
def _a_star_to_target(self, start, target, grid, max_depth=None):
|
| 333 |
+
if start == target:
|
| 334 |
+
return "STAY", f"At target {target}"
|
| 335 |
+
frontier = [(0, start)]
|
| 336 |
+
came_from = {start: None}
|
| 337 |
+
cost_so_far = {start: 0}
|
| 338 |
+
move_map = {}
|
| 339 |
+
depth = 0
|
| 340 |
+
while frontier:
|
| 341 |
+
_, current = heapq.heappop(frontier)
|
| 342 |
+
if current == target or (max_depth and depth >= max_depth):
|
| 343 |
+
break
|
| 344 |
+
depth += 1
|
| 345 |
+
for direction, next_node in self._get_neighbors(current, grid):
|
| 346 |
+
cell_val = grid[next_node[0], next_node[1]]
|
| 347 |
+
move_cost = 50 if cell_val == 1 else 1
|
| 348 |
+
new_cost = cost_so_far[current] + move_cost
|
| 349 |
+
if next_node not in cost_so_far or new_cost < cost_so_far[next_node]:
|
| 350 |
+
cost_so_far[next_node] = new_cost
|
| 351 |
+
priority = new_cost + self._heuristic(next_node, target)
|
| 352 |
+
heapq.heappush(frontier, (priority, next_node))
|
| 353 |
+
came_from[next_node] = current
|
| 354 |
+
move_map[next_node] = direction
|
| 355 |
+
if target in came_from:
|
| 356 |
+
curr = target
|
| 357 |
+
while came_from.get(curr) != start and came_from.get(curr) is not None:
|
| 358 |
+
curr = came_from[curr]
|
| 359 |
+
return move_map.get(curr, "STAY"), f"Path to {target}"
|
| 360 |
+
best_move = "STAY"
|
| 361 |
+
best_dist = self._heuristic(start, target)
|
| 362 |
+
for direction, (nx, ny) in self._get_neighbors(start, grid):
|
| 363 |
+
if grid[nx, ny] != 1:
|
| 364 |
+
d = self._heuristic((nx, ny), target)
|
| 365 |
+
if d < best_dist:
|
| 366 |
+
best_dist = d
|
| 367 |
+
best_move = direction
|
| 368 |
+
return best_move, f"Greedy toward {target}"
|
| 369 |
+
|
| 370 |
+
def _potential_field(self, start, grid, other_agents, target=None):
|
| 371 |
+
best_score = -float('inf')
|
| 372 |
+
best_move = "STAY"
|
| 373 |
+
for direction, (nx, ny) in self._get_neighbors(start, grid):
|
| 374 |
+
score = 0.0
|
| 375 |
+
if grid[nx, ny] == 2: score += 200.0
|
| 376 |
+
elif grid[nx, ny] == 0: score += 1.0
|
| 377 |
+
elif grid[nx, ny] == 1: score -= 100.0
|
| 378 |
+
if (nx, ny) in other_agents: score -= 30.0
|
| 379 |
+
score += random.uniform(0, 3.0)
|
| 380 |
+
if score > best_score:
|
| 381 |
+
best_score = score
|
| 382 |
+
best_move = direction
|
| 383 |
+
return best_move, "Local gradient"
|
| 384 |
+
|
| 385 |
+
def plan(self, start, grid, budget, other_agents, assigned_target=None):
|
| 386 |
+
if assigned_target is None:
|
| 387 |
+
rows, cols = grid.shape
|
| 388 |
+
survivors = [(r, c) for r in range(rows) for c in range(cols) if grid[r, c] == 2]
|
| 389 |
+
if survivors:
|
| 390 |
+
assigned_target = min(survivors, key=lambda t: self._heuristic(start, t))
|
| 391 |
+
else:
|
| 392 |
+
return random.choice(["MOVE_UP", "MOVE_DOWN", "MOVE_LEFT", "MOVE_RIGHT"]), "EXPLORING", "No target"
|
| 393 |
+
|
| 394 |
+
if budget >= 2.0:
|
| 395 |
+
move, msg = self._a_star_to_target(start, assigned_target, grid)
|
| 396 |
+
return move, "STRATEGIC (Full A*)", msg
|
| 397 |
+
elif budget >= 1.0:
|
| 398 |
+
move, msg = self._a_star_to_target(start, assigned_target, grid, max_depth=10)
|
| 399 |
+
return move, "TACTICAL (A* d=10)", msg
|
| 400 |
+
elif budget >= 0.5:
|
| 401 |
+
move, msg = self._a_star_to_target(start, assigned_target, grid, max_depth=3)
|
| 402 |
+
return move, "BALANCED (A* d=3)", msg
|
| 403 |
+
else:
|
| 404 |
+
move, msg = self._potential_field(start, grid, other_agents)
|
| 405 |
+
return move, "REACTIVE (No path)", msg
|
| 406 |
+
|
| 407 |
+
|
| 408 |
+
# ============================================================
|
| 409 |
+
# Q-LEARNING RL TRAINER
|
| 410 |
+
# ============================================================
|
| 411 |
+
class AdaptiveRLTrainer:
|
| 412 |
+
def __init__(self):
|
| 413 |
+
self.episode_count = 0
|
| 414 |
+
self.model_version = 1.0
|
| 415 |
+
self.q_table = {}
|
| 416 |
+
self.experience_replay = deque(maxlen=SimConfig.REPLAY_BUFFER_SIZE)
|
| 417 |
+
self.cumulative_reward = 0.0
|
| 418 |
+
|
| 419 |
+
def get_state_key(self, agent_pos, target):
|
| 420 |
+
return f"{agent_pos}->{target}"
|
| 421 |
+
|
| 422 |
+
def suggest_action(self, agent_pos, target):
|
| 423 |
+
state_key = self.get_state_key(agent_pos, target)
|
| 424 |
+
if state_key not in self.q_table:
|
| 425 |
+
return None
|
| 426 |
+
if random.random() < SimConfig.EPSILON:
|
| 427 |
+
return random.randint(0, 4)
|
| 428 |
+
q_vals = self.q_table[state_key]
|
| 429 |
+
best_action = max(q_vals, key=q_vals.get)
|
| 430 |
+
return best_action if q_vals[best_action] != 0.0 else None
|
| 431 |
+
|
| 432 |
+
def train_step(self, agent_pos, target, action, reward, next_pos, next_target):
|
| 433 |
+
state_key = self.get_state_key(agent_pos, target)
|
| 434 |
+
next_state_key = self.get_state_key(next_pos, next_target)
|
| 435 |
+
self.experience_replay.append((state_key, action, reward, next_state_key))
|
| 436 |
+
for k in [state_key, next_state_key]:
|
| 437 |
+
if k not in self.q_table:
|
| 438 |
+
self.q_table[k] = {0: 0.0, 1: 0.0, 2: 0.0, 3: 0.0, 4: 0.0}
|
| 439 |
+
current_q = self.q_table[state_key][action]
|
| 440 |
+
max_next_q = max(self.q_table[next_state_key].values())
|
| 441 |
+
td_error = reward + SimConfig.DISCOUNT_FACTOR * max_next_q - current_q
|
| 442 |
+
new_q = current_q + SimConfig.LEARNING_RATE * td_error
|
| 443 |
+
self.q_table[state_key][action] = new_q
|
| 444 |
+
if len(self.experience_replay) >= 16:
|
| 445 |
+
batch = random.sample(list(self.experience_replay), 16)
|
| 446 |
+
for sk, a, r, nsk in batch:
|
| 447 |
+
if sk in self.q_table and nsk in self.q_table:
|
| 448 |
+
cq = self.q_table[sk][a]
|
| 449 |
+
mnq = max(self.q_table[nsk].values())
|
| 450 |
+
self.q_table[sk][a] = cq + SimConfig.LEARNING_RATE * (r + SimConfig.DISCOUNT_FACTOR * mnq - cq)
|
| 451 |
+
self.cumulative_reward += reward
|
| 452 |
+
self.episode_count += 1
|
| 453 |
+
if self.episode_count % 10 == 0:
|
| 454 |
+
self.model_version = round(self.model_version + 0.1, 1)
|
| 455 |
+
return abs(td_error), self.model_version
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
# ============================================================
|
| 459 |
+
# RESCUE COMMANDER — Autonomous sense-think-act agent
|
| 460 |
+
# ============================================================
|
| 461 |
+
class RescueCommander:
|
| 462 |
+
def __init__(self, agent_id: int, grid_size: int = SimConfig.GRID_SIZE):
|
| 463 |
+
self.agent_id = agent_id
|
| 464 |
+
self.sensors = SensorFusion()
|
| 465 |
+
self.belief_state = BayesianBeliefState(grid_size)
|
| 466 |
+
self.planner = HierarchicalPlanner()
|
| 467 |
+
self.motion = ProtoMotions()
|
| 468 |
+
self.assigned_target: Optional[Tuple[int, int]] = None
|
| 469 |
+
self.last_mode: str = ""
|
| 470 |
+
|
| 471 |
+
def act(self, observation: Dict, other_agents: Set,
|
| 472 |
+
budget: float, trainer: Optional[AdaptiveRLTrainer] = None) -> Tuple[int, str, str]:
|
| 473 |
+
my_pos = observation['agents'][self.agent_id]
|
| 474 |
+
grid_for_planning = self.belief_state.get_planning_grid()
|
| 475 |
+
move_intent, mode, status = self.planner.plan(
|
| 476 |
+
my_pos, grid_for_planning, budget,
|
| 477 |
+
other_agents, self.assigned_target)
|
| 478 |
+
planner_move = move_intent
|
| 479 |
+
|
| 480 |
+
rl_override = False
|
| 481 |
+
if trainer is not None:
|
| 482 |
+
rl_action = trainer.suggest_action(my_pos, self.assigned_target)
|
| 483 |
+
if rl_action is not None:
|
| 484 |
+
rl_move = ProtoMotions.REVERSE_MAP.get(rl_action)
|
| 485 |
+
if rl_move and rl_move in ProtoMotions.ACTION_MAP:
|
| 486 |
+
move_intent = rl_move
|
| 487 |
+
rl_override = True
|
| 488 |
+
mode = f"{mode}+RL"
|
| 489 |
+
|
| 490 |
+
if move_intent not in ProtoMotions.ACTION_MAP:
|
| 491 |
+
move_intent = planner_move
|
| 492 |
+
|
| 493 |
+
action_code = self.motion.translate_intent(move_intent)
|
| 494 |
+
self.last_mode = mode
|
| 495 |
+
return action_code, move_intent, mode
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
# ============================================================
|
| 499 |
+
# FLEET BELIEF FUSION
|
| 500 |
+
# ============================================================
|
| 501 |
+
def compute_fleet_known_grid(commanders, grid_shape):
|
| 502 |
+
known_grid = np.zeros(grid_shape, dtype=int)
|
| 503 |
+
for commander in commanders.values():
|
| 504 |
+
belief_argmax = commander.belief_state.get_planning_grid()
|
| 505 |
+
scanned = commander.belief_state.get_scanned_mask()
|
| 506 |
+
for r in range(grid_shape[0]):
|
| 507 |
+
for c in range(grid_shape[1]):
|
| 508 |
+
if scanned[r, c]:
|
| 509 |
+
if belief_argmax[r, c] == 2:
|
| 510 |
+
known_grid[r, c] = 2
|
| 511 |
+
elif belief_argmax[r, c] == 1 and known_grid[r, c] != 2:
|
| 512 |
+
known_grid[r, c] = 1
|
| 513 |
+
return known_grid
|
| 514 |
+
|
| 515 |
+
|
| 516 |
+
# ============================================================
|
| 517 |
+
# HEADLESS SIMULATION RUNNER
|
| 518 |
+
# ============================================================
|
| 519 |
+
def run_simulation(
|
| 520 |
+
seed: int,
|
| 521 |
+
budget: float = 2.0,
|
| 522 |
+
priority_sectors: List[int] = None,
|
| 523 |
+
max_steps: int = 100,
|
| 524 |
+
capture_callback=None,
|
| 525 |
+
) -> Dict:
|
| 526 |
+
"""Run a complete MAELSTROM simulation headlessly.
|
| 527 |
+
|
| 528 |
+
Args:
|
| 529 |
+
seed: random seed for reproducibility
|
| 530 |
+
budget: thinking budget (controls scan radius + planner tier)
|
| 531 |
+
priority_sectors: sectors to pre-load intel (simulates Nemotron ON)
|
| 532 |
+
max_steps: maximum simulation steps
|
| 533 |
+
capture_callback: called at each step with (state, commanders,
|
| 534 |
+
coordinator, step, scan_radius) for data capture
|
| 535 |
+
|
| 536 |
+
Returns:
|
| 537 |
+
Dict with final metrics: steps, rescued, outcome, etc.
|
| 538 |
+
"""
|
| 539 |
+
if priority_sectors is None:
|
| 540 |
+
priority_sectors = []
|
| 541 |
+
|
| 542 |
+
np.random.seed(seed)
|
| 543 |
+
random.seed(seed)
|
| 544 |
+
|
| 545 |
+
env = HydroDynamicWorld()
|
| 546 |
+
env.flood_rng = np.random.RandomState(seed + 9999)
|
| 547 |
+
commanders = {i: RescueCommander(i) for i in range(SimConfig.NUM_AGENTS)}
|
| 548 |
+
trainer = AdaptiveRLTrainer()
|
| 549 |
+
coordinator = FleetCoordinator()
|
| 550 |
+
coordinator.set_priority_sectors(priority_sectors)
|
| 551 |
+
|
| 552 |
+
scan_radius = get_scan_radius(budget)
|
| 553 |
+
state = env.reset()
|
| 554 |
+
|
| 555 |
+
# Intel pre-load (Nemotron ON simulation)
|
| 556 |
+
if priority_sectors:
|
| 557 |
+
ground_truth = state['grid']
|
| 558 |
+
for sec_num in priority_sectors:
|
| 559 |
+
if sec_num in SECTOR_GRID:
|
| 560 |
+
r_start, r_end, c_start, c_end = SECTOR_GRID[sec_num]
|
| 561 |
+
intel_observations = {}
|
| 562 |
+
for r in range(r_start, r_end):
|
| 563 |
+
for c in range(c_start, c_end):
|
| 564 |
+
intel_observations[(r, c)] = int(ground_truth[r, c])
|
| 565 |
+
for cmd in commanders.values():
|
| 566 |
+
cmd.belief_state.inject_intel(intel_observations)
|
| 567 |
+
|
| 568 |
+
outcome = "TIMEOUT"
|
| 569 |
+
final_step = max_steps
|
| 570 |
+
|
| 571 |
+
for step in range(max_steps):
|
| 572 |
+
# Scan
|
| 573 |
+
for i, cmd in commanders.items():
|
| 574 |
+
my_pos = state['agents'][cmd.agent_id]
|
| 575 |
+
scan_data = cmd.sensors.scan(state['grid'], my_pos, radius=scan_radius)
|
| 576 |
+
cmd.belief_state.update(scan_data)
|
| 577 |
+
|
| 578 |
+
# Allocate on fleet belief
|
| 579 |
+
fleet_known = compute_fleet_known_grid(commanders, state['grid'].shape)
|
| 580 |
+
assignments = coordinator.allocate_targets(state['agents'], fleet_known)
|
| 581 |
+
for aid, cmd in commanders.items():
|
| 582 |
+
cmd.assigned_target = assignments.get(aid)
|
| 583 |
+
|
| 584 |
+
# Capture callback (for data generation)
|
| 585 |
+
if capture_callback is not None:
|
| 586 |
+
capture_callback(
|
| 587 |
+
state=state,
|
| 588 |
+
commanders=commanders,
|
| 589 |
+
coordinator=coordinator,
|
| 590 |
+
assignments=assignments,
|
| 591 |
+
step=step,
|
| 592 |
+
scan_radius=scan_radius,
|
| 593 |
+
budget=budget,
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
+
# Act
|
| 597 |
+
actions = {}
|
| 598 |
+
other_agents = set(state['agents'].values())
|
| 599 |
+
for i, cmd in commanders.items():
|
| 600 |
+
action, intent, mode = cmd.act(state, other_agents, budget, trainer)
|
| 601 |
+
actions[i] = action
|
| 602 |
+
|
| 603 |
+
# Step environment
|
| 604 |
+
next_state, rewards, done = env.step(actions)
|
| 605 |
+
|
| 606 |
+
# Post-step scan + RL training
|
| 607 |
+
for i, cmd in commanders.items():
|
| 608 |
+
my_pos = next_state['agents'][cmd.agent_id]
|
| 609 |
+
scan_data = cmd.sensors.scan(next_state['grid'], my_pos, radius=scan_radius)
|
| 610 |
+
cmd.belief_state.update(scan_data)
|
| 611 |
+
next_fleet_known = compute_fleet_known_grid(commanders, next_state['grid'].shape)
|
| 612 |
+
next_assignments = coordinator.allocate_targets(next_state['agents'], next_fleet_known)
|
| 613 |
+
for agent_id in actions:
|
| 614 |
+
trainer.train_step(
|
| 615 |
+
state['agents'][agent_id], assignments.get(agent_id),
|
| 616 |
+
actions[agent_id], rewards[agent_id],
|
| 617 |
+
next_state['agents'][agent_id], next_assignments.get(agent_id))
|
| 618 |
+
|
| 619 |
+
if done:
|
| 620 |
+
outcome = "SUCCESS"
|
| 621 |
+
final_step = step + 1
|
| 622 |
+
# One final capture at mission completion
|
| 623 |
+
if capture_callback is not None:
|
| 624 |
+
capture_callback(
|
| 625 |
+
state=next_state,
|
| 626 |
+
commanders=commanders,
|
| 627 |
+
coordinator=coordinator,
|
| 628 |
+
assignments=next_assignments,
|
| 629 |
+
step=step + 1,
|
| 630 |
+
scan_radius=scan_radius,
|
| 631 |
+
budget=budget,
|
| 632 |
+
)
|
| 633 |
+
break
|
| 634 |
+
|
| 635 |
+
state = next_state
|
| 636 |
+
|
| 637 |
+
# Compute explored %
|
| 638 |
+
total_cells = SimConfig.GRID_SIZE * SimConfig.GRID_SIZE
|
| 639 |
+
global_scanned = np.zeros((SimConfig.GRID_SIZE, SimConfig.GRID_SIZE), dtype=bool)
|
| 640 |
+
for cmd in commanders.values():
|
| 641 |
+
global_scanned |= cmd.belief_state.get_scanned_mask()
|
| 642 |
+
explored_pct = int(100 * global_scanned.sum() / total_cells)
|
| 643 |
+
|
| 644 |
+
return {
|
| 645 |
+
'seed': seed,
|
| 646 |
+
'budget': budget,
|
| 647 |
+
'priority_sectors': priority_sectors,
|
| 648 |
+
'steps': final_step,
|
| 649 |
+
'rescued': state['rescued'] if outcome == "TIMEOUT" else next_state['rescued'],
|
| 650 |
+
'outcome': outcome,
|
| 651 |
+
'explored_pct': explored_pct,
|
| 652 |
+
'avg_reward': round(trainer.cumulative_reward / max(trainer.episode_count, 1), 3),
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
|
| 656 |
+
if __name__ == "__main__":
|
| 657 |
+
# Quick validation
|
| 658 |
+
result = run_simulation(seed=42, budget=2.0, priority_sectors=[])
|
| 659 |
+
print(f"Seed 42, budget 2.0, no intel: {result['outcome']} in {result['steps']} steps, "
|
| 660 |
+
f"rescued {result['rescued']}, explored {result['explored_pct']}%")
|
| 661 |
+
|
| 662 |
+
result = run_simulation(seed=42, budget=2.0, priority_sectors=[4, 7])
|
| 663 |
+
print(f"Seed 42, budget 2.0, sectors [4,7]: {result['outcome']} in {result['steps']} steps, "
|
| 664 |
+
f"rescued {result['rescued']}, explored {result['explored_pct']}%")
|
aegis-reason/aegis-reason/requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AEGIS-Reason — CPU dependencies (data generation + evaluation)
|
| 2 |
+
numpy>=1.24
|
| 3 |
+
Pillow>=10.0
|
| 4 |
+
matplotlib>=3.7
|
| 5 |
+
|
| 6 |
+
# GPU dependencies (training + inference — install on Nebius)
|
| 7 |
+
# torch>=2.1
|
| 8 |
+
# transformers>=4.40
|
| 9 |
+
# huggingface_hub>=0.20
|
aegis-reason/aegis-reason/samples/egocentric_sample.png
ADDED
|
aegis-reason/aegis-reason/samples/sample_chain.json
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"step": 4,
|
| 3 |
+
"rescued": 2,
|
| 4 |
+
"num_survivors_remaining": 5,
|
| 5 |
+
"num_hazard_cells": 18,
|
| 6 |
+
"spatial_reasoning": "Grid: 20\u00d720. 5 survivors remaining. 18 flood cells. Robot 0: position (12,11), sector 11. Robot 1: position (10,4), sector 9. Robot 2: position (16,6), sector 14. Survivor at (1,15), sector 4. Nearest robot: 0 (distance 15). Survivor at (12,15), sector 12. Nearest robot: 0 (distance 4). Survivor at (13,11), sector 11. Nearest robot: 0 (distance 1). Survivor at (16,12), sector 15. Nearest robot: 0 (distance 5). Survivor at (18,9), sector 14. Nearest robot: 2 (distance 5).",
|
| 7 |
+
"temporal_reasoning": "Current step: 4. Flood cells: 18. Frontier cells: 18. Flood expanding stationary. Predicted flood cells at step 7: ~22. Predicted flood cells at step 9: ~25. Predicted flood cells at step 14: ~32.",
|
| 8 |
+
"causal_reasoning": "Survivor (1,15): urgency CRITICAL \u2014 flood frontier is 2 cells away. Nearest robot: 0 at distance 15. Survivor (12,15): urgency STANDARD \u2014 accessible, no immediate threat. Nearest robot: 0 at distance 4. Survivor (13,11): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 0 at distance 1. Survivor (16,12): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 0 at distance 5. Survivor (18,9): urgency CRITICAL \u2014 flood frontier is 1 cells away. Nearest robot: 2 at distance 5. Causal factors: rescue probability depends on (1) robot-survivor distance, (2) flood proximity to survivor, (3) path traversability, (4) competing allocation demands from other survivors.",
|
| 9 |
+
"decision_reasoning": "Recommended: Robot 0 (12,11) \u2192 survivor (13,11), sector 11, distance 1 steps. Recommended: Robot 2 (16,6) \u2192 survivor (18,9), sector 14, distance 5 steps. Recommended: Robot 1 (10,4) \u2192 survivor (12,15), sector 12, distance 13 steps. Survivors remaining to rescue: 3. Target: 5 total.",
|
| 10 |
+
"full_chain": "[SPATIAL GROUNDING] Grid: 20\u00d720. 5 survivors remaining. 18 flood cells. Robot 0: position (12,11), sector 11. Robot 1: position (10,4), sector 9. Robot 2: position (16,6), sector 14. Survivor at (1,15), sector 4. Nearest robot: 0 (distance 15). Survivor at (12,15), sector 12. Nearest robot: 0 (distance 4). Survivor at (13,11), sector 11. Nearest robot: 0 (distance 1). Survivor at (16,12), sector 15. Nearest robot: 0 (distance 5). Survivor at (18,9), sector 14. Nearest robot: 2 (distance 5).\n\n[TEMPORAL DYNAMICS] Current step: 4. Flood cells: 18. Frontier cells: 18. Flood expanding stationary. Predicted flood cells at step 7: ~22. Predicted flood cells at step 9: ~25. Predicted flood cells at step 14: ~32.\n\n[CAUSAL REASONING] Survivor (1,15): urgency CRITICAL \u2014 flood frontier is 2 cells away. Nearest robot: 0 at distance 15. Survivor (12,15): urgency STANDARD \u2014 accessible, no immediate threat. Nearest robot: 0 at distance 4. Survivor (13,11): urgency HIGH \u2014 flood approaching (5 cells). Nearest robot: 0 at distance 1. Survivor (16,12): urgency HIGH \u2014 flood approaching (3 cells). Nearest robot: 0 at distance 5. Survivor (18,9): urgency CRITICAL \u2014 flood frontier is 1 cells away. Nearest robot: 2 at distance 5. Causal factors: rescue probability depends on (1) robot-survivor distance, (2) flood proximity to survivor, (3) path traversability, (4) competing allocation demands from other survivors.\n\n[DECISION] Recommended: Robot 0 (12,11) \u2192 survivor (13,11), sector 11, distance 1 steps. Recommended: Robot 2 (16,6) \u2192 survivor (18,9), sector 14, distance 5 steps. Recommended: Robot 1 (10,4) \u2192 survivor (12,15), sector 12, distance 13 steps. Survivors remaining to rescue: 3. Target: 5 total."
|
| 11 |
+
}
|
aegis-reason/aegis-reason/samples/topdown_step0.png
ADDED
|
aegis-reason/aegis-reason/samples/topdown_step4.png
ADDED
|
aegis-reason/aegis-reason/scripts/aegis_e2e_test.py
ADDED
|
@@ -0,0 +1,393 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
AEGIS End-to-End Validation
|
| 4 |
+
============================
|
| 5 |
+
Runs a miniature version of the full AEGIS pipeline to verify
|
| 6 |
+
all components work together. Takes ~30 seconds on any CPU.
|
| 7 |
+
|
| 8 |
+
Tests:
|
| 9 |
+
1. MAELSTROM simulation runs deterministically
|
| 10 |
+
2. Rendering produces valid PNGs
|
| 11 |
+
3. Reasoning chain generation is well-formed
|
| 12 |
+
4. SFT data converter produces valid LLaVA JSON
|
| 13 |
+
5. VARP evaluation scores correctly
|
| 14 |
+
6. GRPO reward function has proper spread
|
| 15 |
+
|
| 16 |
+
Usage:
|
| 17 |
+
python aegis_e2e_test.py
|
| 18 |
+
"""
|
| 19 |
+
|
| 20 |
+
import sys
|
| 21 |
+
import os
|
| 22 |
+
import json
|
| 23 |
+
import tempfile
|
| 24 |
+
import time
|
| 25 |
+
import traceback
|
| 26 |
+
import numpy as np
|
| 27 |
+
|
| 28 |
+
PASS = "✓"
|
| 29 |
+
FAIL = "✗"
|
| 30 |
+
results = []
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test(name, func):
|
| 34 |
+
"""Run a test and record result."""
|
| 35 |
+
try:
|
| 36 |
+
start = time.time()
|
| 37 |
+
func()
|
| 38 |
+
elapsed = time.time() - start
|
| 39 |
+
results.append((name, True, f"{elapsed:.1f}s"))
|
| 40 |
+
print(f" {PASS} {name} ({elapsed:.1f}s)")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
results.append((name, False, str(e)))
|
| 43 |
+
print(f" {FAIL} {name}: {e}")
|
| 44 |
+
traceback.print_exc()
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
# ============================================================
|
| 48 |
+
# Test 1: Simulation determinism
|
| 49 |
+
# ============================================================
|
| 50 |
+
def test_simulation():
|
| 51 |
+
from maelstrom_core import run_simulation
|
| 52 |
+
|
| 53 |
+
r1 = run_simulation(seed=42, budget=2.0)
|
| 54 |
+
r2 = run_simulation(seed=42, budget=2.0)
|
| 55 |
+
assert r1['steps'] == r2['steps'], f"Non-deterministic: {r1['steps']} vs {r2['steps']}"
|
| 56 |
+
assert r1['rescued'] == r2['rescued'], f"Rescued mismatch: {r1['rescued']} vs {r2['rescued']}"
|
| 57 |
+
assert r1['outcome'] in ('SUCCESS', 'TIMEOUT'), f"Bad outcome: {r1['outcome']}"
|
| 58 |
+
assert 0 <= r1['explored_pct'] <= 100, f"Bad explored: {r1['explored_pct']}"
|
| 59 |
+
|
| 60 |
+
# Test different budgets produce different results
|
| 61 |
+
r3 = run_simulation(seed=42, budget=0.3)
|
| 62 |
+
# Low budget should generally perform worse or differently
|
| 63 |
+
assert isinstance(r3['rescued'], int)
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# ============================================================
|
| 67 |
+
# Test 2: Rendering pipeline
|
| 68 |
+
# ============================================================
|
| 69 |
+
def test_rendering():
|
| 70 |
+
from maelstrom_core import run_simulation, SimConfig
|
| 71 |
+
from aegis_render_engine import TopDownRenderer, EgocentricRenderer, ReasoningChainGenerator
|
| 72 |
+
|
| 73 |
+
# Run a short sim with capture
|
| 74 |
+
frames = []
|
| 75 |
+
|
| 76 |
+
def capture(state, commanders, coordinator, assignments, step, scan_radius, budget, **kw):
|
| 77 |
+
if step < 3:
|
| 78 |
+
frames.append({
|
| 79 |
+
'state': state,
|
| 80 |
+
'commanders': commanders,
|
| 81 |
+
'assignments': assignments,
|
| 82 |
+
'step': step,
|
| 83 |
+
'scan_radius': scan_radius,
|
| 84 |
+
'budget': budget,
|
| 85 |
+
})
|
| 86 |
+
|
| 87 |
+
run_simulation(seed=7, budget=2.0, capture_callback=capture)
|
| 88 |
+
assert len(frames) >= 2, f"Expected >= 2 frames, got {len(frames)}"
|
| 89 |
+
|
| 90 |
+
# Render top-down (cell_size=32 → 32*20=640)
|
| 91 |
+
td = TopDownRenderer(cell_size=32)
|
| 92 |
+
with tempfile.NamedTemporaryFile(suffix='.png', delete=False) as f:
|
| 93 |
+
td_path = f.name
|
| 94 |
+
|
| 95 |
+
frame = frames[0]
|
| 96 |
+
img = td.render(
|
| 97 |
+
grid=frame['state']['grid'],
|
| 98 |
+
agent_positions=frame['state']['agents'],
|
| 99 |
+
rescued=frame['state']['rescued'],
|
| 100 |
+
step=frame['step'],
|
| 101 |
+
assignments=frame['assignments'],
|
| 102 |
+
scan_radius=frame['scan_radius'],
|
| 103 |
+
)
|
| 104 |
+
img.save(td_path)
|
| 105 |
+
size = os.path.getsize(td_path)
|
| 106 |
+
assert size > 1000, f"Top-down PNG too small: {size} bytes"
|
| 107 |
+
assert img.size[0] >= 400, f"Image too small: {img.size}"
|
| 108 |
+
os.unlink(td_path)
|
| 109 |
+
|
| 110 |
+
# Render egocentric
|
| 111 |
+
ego = EgocentricRenderer(output_size=640)
|
| 112 |
+
from maelstrom_core import BayesianBeliefState
|
| 113 |
+
belief = BayesianBeliefState(SimConfig.GRID_SIZE)
|
| 114 |
+
ego_img = ego.render(
|
| 115 |
+
grid=frame['state']['grid'],
|
| 116 |
+
agent_id=0,
|
| 117 |
+
agent_positions=frame['state']['agents'],
|
| 118 |
+
belief_grid=belief.get_planning_grid(),
|
| 119 |
+
scan_radius=frame['scan_radius'],
|
| 120 |
+
)
|
| 121 |
+
assert ego_img.size[0] >= 400, f"Ego too small: {ego_img.size}"
|
| 122 |
+
|
| 123 |
+
# Generate chain
|
| 124 |
+
cg = ReasoningChainGenerator()
|
| 125 |
+
chain = cg.generate(
|
| 126 |
+
grid=frame['state']['grid'],
|
| 127 |
+
agent_positions=frame['state']['agents'],
|
| 128 |
+
rescued=frame['state']['rescued'],
|
| 129 |
+
step=frame['step'],
|
| 130 |
+
assignments=frame['assignments'],
|
| 131 |
+
scan_radius=frame['scan_radius'],
|
| 132 |
+
)
|
| 133 |
+
assert 'spatial_reasoning' in chain
|
| 134 |
+
assert 'temporal_reasoning' in chain
|
| 135 |
+
assert 'causal_reasoning' in chain
|
| 136 |
+
assert 'decision_reasoning' in chain
|
| 137 |
+
assert 'full_chain' in chain
|
| 138 |
+
assert len(chain['full_chain']) > 100, f"Chain too short: {len(chain['full_chain'])}"
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
# ============================================================
|
| 142 |
+
# Test 3: Data generator (mini run)
|
| 143 |
+
# ============================================================
|
| 144 |
+
def test_data_generation():
|
| 145 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 146 |
+
from aegis_data_generator import AEGISBatchGenerator, DatasetConfig
|
| 147 |
+
|
| 148 |
+
# Customize config for mini run
|
| 149 |
+
DatasetConfig.SEEDS = [1, 2]
|
| 150 |
+
DatasetConfig.BUDGETS = [2.0]
|
| 151 |
+
DatasetConfig.INTEL_MODE = False
|
| 152 |
+
DatasetConfig.CAPTURE_INTERVAL = 10
|
| 153 |
+
DatasetConfig.OUTPUT_DIR = tmpdir
|
| 154 |
+
DatasetConfig.RENDER_EGOCENTRIC = False # Speed
|
| 155 |
+
|
| 156 |
+
gen = AEGISBatchGenerator()
|
| 157 |
+
stats = gen.generate_all()
|
| 158 |
+
|
| 159 |
+
# Check outputs exist
|
| 160 |
+
assert os.path.exists(os.path.join(tmpdir, 'sft_data.jsonl'))
|
| 161 |
+
assert os.path.exists(os.path.join(tmpdir, 'manifest.json'))
|
| 162 |
+
|
| 163 |
+
# Count records
|
| 164 |
+
with open(os.path.join(tmpdir, 'sft_data.jsonl')) as f:
|
| 165 |
+
lines = f.readlines()
|
| 166 |
+
assert len(lines) > 0, "No SFT records generated"
|
| 167 |
+
|
| 168 |
+
# Validate first record
|
| 169 |
+
record = json.loads(lines[0])
|
| 170 |
+
assert 'id' in record
|
| 171 |
+
assert 'conversations' in record
|
| 172 |
+
|
| 173 |
+
# Check frames exist
|
| 174 |
+
td_files = os.listdir(os.path.join(tmpdir, 'topdown'))
|
| 175 |
+
assert len(td_files) > 0, "No topdown frames"
|
| 176 |
+
|
| 177 |
+
chain_files = os.listdir(os.path.join(tmpdir, 'chains'))
|
| 178 |
+
assert len(chain_files) > 0, "No chain files"
|
| 179 |
+
|
| 180 |
+
# Reset config
|
| 181 |
+
DatasetConfig.SEEDS = list(range(1, 41))
|
| 182 |
+
DatasetConfig.BUDGETS = [0.3, 1.0, 2.0, 3.0]
|
| 183 |
+
DatasetConfig.INTEL_MODE = True
|
| 184 |
+
DatasetConfig.CAPTURE_INTERVAL = 3
|
| 185 |
+
DatasetConfig.RENDER_EGOCENTRIC = True
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# ============================================================
|
| 189 |
+
# Test 4: LLaVA converter
|
| 190 |
+
# ============================================================
|
| 191 |
+
def test_llava_converter():
|
| 192 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 193 |
+
from aegis_data_generator import AEGISBatchGenerator, DatasetConfig
|
| 194 |
+
|
| 195 |
+
DatasetConfig.SEEDS = [1]
|
| 196 |
+
DatasetConfig.BUDGETS = [2.0]
|
| 197 |
+
DatasetConfig.INTEL_MODE = False
|
| 198 |
+
DatasetConfig.CAPTURE_INTERVAL = 10
|
| 199 |
+
DatasetConfig.OUTPUT_DIR = os.path.join(tmpdir, 'dataset')
|
| 200 |
+
DatasetConfig.RENDER_EGOCENTRIC = False
|
| 201 |
+
|
| 202 |
+
gen = AEGISBatchGenerator()
|
| 203 |
+
gen.generate_all()
|
| 204 |
+
|
| 205 |
+
# Reset config
|
| 206 |
+
DatasetConfig.SEEDS = list(range(1, 41))
|
| 207 |
+
DatasetConfig.BUDGETS = [0.3, 1.0, 2.0, 3.0]
|
| 208 |
+
DatasetConfig.INTEL_MODE = True
|
| 209 |
+
DatasetConfig.CAPTURE_INTERVAL = 3
|
| 210 |
+
DatasetConfig.RENDER_EGOCENTRIC = True
|
| 211 |
+
|
| 212 |
+
# Convert
|
| 213 |
+
from aegis_convert_llava import convert_aegis_to_llava
|
| 214 |
+
stats = convert_aegis_to_llava(
|
| 215 |
+
input_jsonl=os.path.join(tmpdir, 'dataset', 'sft_data.jsonl'),
|
| 216 |
+
output_dir=os.path.join(tmpdir, 'llava'),
|
| 217 |
+
val_ratio=0.2,
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
assert stats['total'] > 0, "No records converted"
|
| 221 |
+
assert stats['train'] > 0, "No training records"
|
| 222 |
+
|
| 223 |
+
# Validate LLaVA format
|
| 224 |
+
with open(stats['train_path']) as f:
|
| 225 |
+
data = json.load(f)
|
| 226 |
+
entry = data[0]
|
| 227 |
+
assert 'id' in entry
|
| 228 |
+
assert 'image' in entry
|
| 229 |
+
assert 'conversations' in entry
|
| 230 |
+
assert entry['conversations'][0]['from'] == 'human'
|
| 231 |
+
assert entry['conversations'][1]['from'] == 'gpt'
|
| 232 |
+
assert '<image>' in entry['conversations'][0]['value']
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
# ============================================================
|
| 236 |
+
# Test 5: VARP evaluation
|
| 237 |
+
# ============================================================
|
| 238 |
+
def test_varp():
|
| 239 |
+
from aegis_varp import VARPEvaluator
|
| 240 |
+
|
| 241 |
+
evaluator = VARPEvaluator()
|
| 242 |
+
|
| 243 |
+
# Load a real chain (skip if dataset not generated yet)
|
| 244 |
+
chains_dir = 'aegis_dataset/chains/'
|
| 245 |
+
if not os.path.isdir(chains_dir):
|
| 246 |
+
print(" (no dataset found, generating mini dataset for VARP test)")
|
| 247 |
+
# Generate a tiny dataset for testing
|
| 248 |
+
from aegis_data_generator import AEGISBatchGenerator, DatasetConfig
|
| 249 |
+
DatasetConfig.SEEDS = [99]
|
| 250 |
+
DatasetConfig.BUDGETS = [2.0]
|
| 251 |
+
DatasetConfig.INTEL_MODE = False
|
| 252 |
+
DatasetConfig.CAPTURE_INTERVAL = 20
|
| 253 |
+
DatasetConfig.OUTPUT_DIR = 'aegis_dataset'
|
| 254 |
+
DatasetConfig.RENDER_EGOCENTRIC = False
|
| 255 |
+
gen = AEGISBatchGenerator()
|
| 256 |
+
gen.generate_all()
|
| 257 |
+
# Reset
|
| 258 |
+
DatasetConfig.SEEDS = list(range(1, 41))
|
| 259 |
+
DatasetConfig.BUDGETS = [0.3, 1.0, 2.0, 3.0]
|
| 260 |
+
DatasetConfig.INTEL_MODE = True
|
| 261 |
+
DatasetConfig.CAPTURE_INTERVAL = 3
|
| 262 |
+
DatasetConfig.RENDER_EGOCENTRIC = True
|
| 263 |
+
|
| 264 |
+
chain_files = sorted(os.listdir(chains_dir))[:5]
|
| 265 |
+
if not chain_files:
|
| 266 |
+
# Generate mini dataset if none exists
|
| 267 |
+
return
|
| 268 |
+
|
| 269 |
+
for cf in chain_files:
|
| 270 |
+
with open(os.path.join(chains_dir, cf)) as f:
|
| 271 |
+
gt = json.load(f)
|
| 272 |
+
|
| 273 |
+
# Perfect prediction
|
| 274 |
+
r = evaluator.evaluate_single(gt['full_chain'], gt)
|
| 275 |
+
assert 0.5 < r['varp_score'] <= 1.0, f"Perfect VARP too low: {r['varp_score']}"
|
| 276 |
+
|
| 277 |
+
# Vague prediction
|
| 278 |
+
r2 = evaluator.evaluate_single("Robots and floods exist.", gt)
|
| 279 |
+
assert r2['varp_score'] < 0.3, f"Vague VARP too high: {r2['varp_score']}"
|
| 280 |
+
|
| 281 |
+
# Spread
|
| 282 |
+
spread = r['varp_score'] - r2['varp_score']
|
| 283 |
+
assert spread > 0.3, f"VARP spread too small: {spread}"
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
# ============================================================
|
| 287 |
+
# Test 6: GRPO reward function
|
| 288 |
+
# ============================================================
|
| 289 |
+
def test_grpo_reward():
|
| 290 |
+
import re
|
| 291 |
+
|
| 292 |
+
# Inline reward (can't import torch-dependent module)
|
| 293 |
+
def score_spatial(pred, gt):
|
| 294 |
+
gt_text = gt.get('spatial_reasoning', '')
|
| 295 |
+
robots, survivors = [], []
|
| 296 |
+
for m in re.finditer(r'Robot (\d+): position \((\d+),(\d+)\)', gt_text):
|
| 297 |
+
robots.append([int(m.group(2)), int(m.group(3))])
|
| 298 |
+
for m in re.finditer(r'Survivor at \((\d+),(\d+)\)', gt_text):
|
| 299 |
+
survivors.append([int(m.group(1)), int(m.group(2))])
|
| 300 |
+
total = len(robots) + len(survivors)
|
| 301 |
+
if total == 0: return 1.0
|
| 302 |
+
found = sum(1 for p in robots + survivors if f"({p[0]},{p[1]})" in pred.replace(' ', ''))
|
| 303 |
+
return found / total
|
| 304 |
+
|
| 305 |
+
chains_dir = 'aegis_dataset/chains/'
|
| 306 |
+
if not os.path.isdir(chains_dir):
|
| 307 |
+
return # VARP test already generates mini dataset if needed
|
| 308 |
+
|
| 309 |
+
chain_files = sorted(os.listdir(chains_dir))[:5]
|
| 310 |
+
if not chain_files:
|
| 311 |
+
return
|
| 312 |
+
|
| 313 |
+
rewards_perfect, rewards_vague = [], []
|
| 314 |
+
for cf in chain_files:
|
| 315 |
+
with open(os.path.join(chains_dir, cf)) as f:
|
| 316 |
+
gt = json.load(f)
|
| 317 |
+
rp = score_spatial(gt['full_chain'], gt)
|
| 318 |
+
rv = score_spatial("nothing here", gt)
|
| 319 |
+
rewards_perfect.append(rp)
|
| 320 |
+
rewards_vague.append(rv)
|
| 321 |
+
|
| 322 |
+
avg_perfect = np.mean(rewards_perfect)
|
| 323 |
+
avg_vague = np.mean(rewards_vague)
|
| 324 |
+
assert avg_perfect > 0.8, f"Perfect spatial too low: {avg_perfect}"
|
| 325 |
+
assert avg_vague < 0.2, f"Vague spatial too high: {avg_vague}"
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
# ============================================================
|
| 329 |
+
# Test 7: Config files parse correctly
|
| 330 |
+
# ============================================================
|
| 331 |
+
def test_configs():
|
| 332 |
+
for cfg_file in ['configs/aegis_sft.toml', 'configs/aegis_grpo.toml',
|
| 333 |
+
'aegis_sft.toml', 'aegis_grpo.toml']:
|
| 334 |
+
if not os.path.exists(cfg_file):
|
| 335 |
+
continue
|
| 336 |
+
with open(cfg_file, 'rb') as f:
|
| 337 |
+
if sys.version_info >= (3, 11):
|
| 338 |
+
import tomllib
|
| 339 |
+
config = tomllib.load(f)
|
| 340 |
+
assert 'train' in config, f"Missing [train] in {cfg_file}"
|
| 341 |
+
assert 'policy' in config, f"Missing [policy] in {cfg_file}"
|
| 342 |
+
else:
|
| 343 |
+
content = f.read().decode()
|
| 344 |
+
assert '[train]' in content, f"Missing [train] in {cfg_file}"
|
| 345 |
+
assert '[policy]' in content, f"Missing [policy] in {cfg_file}"
|
| 346 |
+
|
| 347 |
+
|
| 348 |
+
# ============================================================
|
| 349 |
+
# Run all tests
|
| 350 |
+
# ============================================================
|
| 351 |
+
def main():
|
| 352 |
+
print("=" * 60)
|
| 353 |
+
print("AEGIS End-to-End Validation")
|
| 354 |
+
print("=" * 60)
|
| 355 |
+
print()
|
| 356 |
+
|
| 357 |
+
# Find repo root: if we're in scripts/, go up one level
|
| 358 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 359 |
+
if os.path.basename(script_dir) == 'scripts':
|
| 360 |
+
repo_root = os.path.dirname(script_dir)
|
| 361 |
+
else:
|
| 362 |
+
repo_root = script_dir
|
| 363 |
+
os.chdir(repo_root)
|
| 364 |
+
sys.path.insert(0, repo_root)
|
| 365 |
+
print(f" Working directory: {repo_root}")
|
| 366 |
+
print()
|
| 367 |
+
|
| 368 |
+
test("1. Simulation determinism", test_simulation)
|
| 369 |
+
test("2. Rendering pipeline", test_rendering)
|
| 370 |
+
test("3. Data generation (mini)", test_data_generation)
|
| 371 |
+
test("4. LLaVA converter", test_llava_converter)
|
| 372 |
+
test("5. VARP evaluation", test_varp)
|
| 373 |
+
test("6. GRPO reward spread", test_grpo_reward)
|
| 374 |
+
test("7. Config files", test_configs)
|
| 375 |
+
|
| 376 |
+
print()
|
| 377 |
+
print("=" * 60)
|
| 378 |
+
passed = sum(1 for _, ok, _ in results if ok)
|
| 379 |
+
total = len(results)
|
| 380 |
+
status = "ALL PASSED" if passed == total else f"{total - passed} FAILED"
|
| 381 |
+
print(f"Results: {passed}/{total} passed — {status}")
|
| 382 |
+
print("=" * 60)
|
| 383 |
+
|
| 384 |
+
if passed < total:
|
| 385 |
+
print("\nFailed tests:")
|
| 386 |
+
for name, ok, msg in results:
|
| 387 |
+
if not ok:
|
| 388 |
+
print(f" {FAIL} {name}: {msg}")
|
| 389 |
+
sys.exit(1)
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
if __name__ == "__main__":
|
| 393 |
+
main()
|
aegis-reason/aegis-reason/scripts/nebius_train.sh
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# ============================================================
|
| 3 |
+
# AEGIS Post-Training — Nebius H100 Setup & Launch
|
| 4 |
+
# ============================================================
|
| 5 |
+
# One-shot script to set up a Nebius GPU instance and run
|
| 6 |
+
# Cosmos Reason 2 SFT on the AEGIS disaster rescue dataset.
|
| 7 |
+
#
|
| 8 |
+
# Prerequisites:
|
| 9 |
+
# - Nebius H100 instance (8× H100 80GB recommended)
|
| 10 |
+
# - Ubuntu 22.04/24.04 with NVIDIA drivers + CUDA 12.x
|
| 11 |
+
# - HF_TOKEN environment variable set
|
| 12 |
+
# - WANDB_API_KEY environment variable set
|
| 13 |
+
#
|
| 14 |
+
# Usage:
|
| 15 |
+
# # Upload AEGIS dataset to the instance first, then:
|
| 16 |
+
# chmod +x nebius_train.sh
|
| 17 |
+
# ./nebius_train.sh [--model 2b|8b] [--epochs 5] [--data-dir /data/aegis]
|
| 18 |
+
#
|
| 19 |
+
# Estimated training time:
|
| 20 |
+
# - 2B model, 12K samples, 5 epochs: ~45 min on 8× H100
|
| 21 |
+
# - 8B model, 12K samples, 3 epochs: ~3-4 hours on 8× H100
|
| 22 |
+
# ============================================================
|
| 23 |
+
|
| 24 |
+
set -euo pipefail
|
| 25 |
+
|
| 26 |
+
# ============================================================
|
| 27 |
+
# Configuration (override via command-line args)
|
| 28 |
+
# ============================================================
|
| 29 |
+
MODEL_SIZE="${MODEL_SIZE:-2b}" # "2b" or "8b"
|
| 30 |
+
NUM_EPOCHS="${NUM_EPOCHS:-5}"
|
| 31 |
+
DATA_DIR="${DATA_DIR:-/data/aegis}"
|
| 32 |
+
OUTPUT_DIR="${OUTPUT_DIR:-/data/aegis/outputs}"
|
| 33 |
+
LR="${LR:-5e-6}"
|
| 34 |
+
|
| 35 |
+
# Parse command-line arguments
|
| 36 |
+
while [[ $# -gt 0 ]]; do
|
| 37 |
+
case $1 in
|
| 38 |
+
--model) MODEL_SIZE="$2"; shift 2 ;;
|
| 39 |
+
--epochs) NUM_EPOCHS="$2"; shift 2 ;;
|
| 40 |
+
--data-dir) DATA_DIR="$2"; shift 2 ;;
|
| 41 |
+
--lr) LR="$2"; shift 2 ;;
|
| 42 |
+
--help)
|
| 43 |
+
echo "Usage: $0 [--model 2b|8b] [--epochs N] [--data-dir PATH] [--lr RATE]"
|
| 44 |
+
exit 0 ;;
|
| 45 |
+
*) echo "Unknown arg: $1"; exit 1 ;;
|
| 46 |
+
esac
|
| 47 |
+
done
|
| 48 |
+
|
| 49 |
+
# Model-specific settings
|
| 50 |
+
if [[ "$MODEL_SIZE" == "8b" ]]; then
|
| 51 |
+
MODEL_NAME="nvidia/Cosmos-Reason2-8B"
|
| 52 |
+
TP_SIZE=2
|
| 53 |
+
DP_SIZE=4
|
| 54 |
+
BATCH_SIZE=8
|
| 55 |
+
MAX_LEN=4096
|
| 56 |
+
LR="${LR:-2e-6}"
|
| 57 |
+
else
|
| 58 |
+
MODEL_NAME="nvidia/Cosmos-Reason2-2B"
|
| 59 |
+
TP_SIZE=1
|
| 60 |
+
DP_SIZE=8
|
| 61 |
+
BATCH_SIZE=16
|
| 62 |
+
MAX_LEN=4096
|
| 63 |
+
LR="${LR:-5e-6}"
|
| 64 |
+
fi
|
| 65 |
+
|
| 66 |
+
echo "============================================================"
|
| 67 |
+
echo "AEGIS Post-Training Pipeline"
|
| 68 |
+
echo "============================================================"
|
| 69 |
+
echo " Model: $MODEL_NAME"
|
| 70 |
+
echo " Epochs: $NUM_EPOCHS"
|
| 71 |
+
echo " Learning rate: $LR"
|
| 72 |
+
echo " Batch/GPU: $BATCH_SIZE"
|
| 73 |
+
echo " Parallelism: TP=$TP_SIZE, DP=$DP_SIZE"
|
| 74 |
+
echo " Data dir: $DATA_DIR"
|
| 75 |
+
echo " Output dir: $OUTPUT_DIR"
|
| 76 |
+
echo "============================================================"
|
| 77 |
+
|
| 78 |
+
# ============================================================
|
| 79 |
+
# Step 0: Verify environment
|
| 80 |
+
# ============================================================
|
| 81 |
+
echo ""
|
| 82 |
+
echo "[Step 0] Verifying environment..."
|
| 83 |
+
|
| 84 |
+
# Check GPU
|
| 85 |
+
if ! command -v nvidia-smi &> /dev/null; then
|
| 86 |
+
echo "ERROR: nvidia-smi not found. Ensure NVIDIA drivers are installed."
|
| 87 |
+
exit 1
|
| 88 |
+
fi
|
| 89 |
+
GPU_COUNT=$(nvidia-smi --query-gpu=count --format=csv,noheader | head -1)
|
| 90 |
+
echo " GPUs detected: $GPU_COUNT"
|
| 91 |
+
|
| 92 |
+
# Check tokens
|
| 93 |
+
if [[ -z "${HF_TOKEN:-}" ]]; then
|
| 94 |
+
echo "ERROR: HF_TOKEN not set. Run: export HF_TOKEN=your_token"
|
| 95 |
+
exit 1
|
| 96 |
+
fi
|
| 97 |
+
echo " HF_TOKEN: set"
|
| 98 |
+
|
| 99 |
+
if [[ -z "${WANDB_API_KEY:-}" ]]; then
|
| 100 |
+
echo "WARNING: WANDB_API_KEY not set. Training will proceed without wandb logging."
|
| 101 |
+
echo " Set it with: export WANDB_API_KEY=your_key"
|
| 102 |
+
fi
|
| 103 |
+
|
| 104 |
+
# Check data
|
| 105 |
+
if [[ ! -f "$DATA_DIR/aegis_llava/annotations_train.json" ]]; then
|
| 106 |
+
echo "ERROR: Training annotations not found at $DATA_DIR/aegis_llava/annotations_train.json"
|
| 107 |
+
echo " Upload the AEGIS dataset first, or run the converter:"
|
| 108 |
+
echo " python3 aegis_convert_llava.py --input $DATA_DIR/aegis_dataset/sft_data.jsonl --output $DATA_DIR/aegis_llava"
|
| 109 |
+
exit 1
|
| 110 |
+
fi
|
| 111 |
+
TRAIN_SAMPLES=$(python3 -c "import json; print(len(json.load(open('$DATA_DIR/aegis_llava/annotations_train.json'))))")
|
| 112 |
+
echo " Training samples: $TRAIN_SAMPLES"
|
| 113 |
+
echo " Environment OK!"
|
| 114 |
+
|
| 115 |
+
# ============================================================
|
| 116 |
+
# Step 1: Clone and install cosmos-reason2 + cosmos-rl
|
| 117 |
+
# ============================================================
|
| 118 |
+
echo ""
|
| 119 |
+
echo "[Step 1] Setting up cosmos-reason2 and cosmos-rl..."
|
| 120 |
+
|
| 121 |
+
COSMOS_DIR="$DATA_DIR/cosmos-reason2"
|
| 122 |
+
|
| 123 |
+
if [[ ! -d "$COSMOS_DIR" ]]; then
|
| 124 |
+
echo " Cloning cosmos-reason2..."
|
| 125 |
+
git clone https://github.com/nvidia-cosmos/cosmos-reason2.git "$COSMOS_DIR"
|
| 126 |
+
else
|
| 127 |
+
echo " cosmos-reason2 already cloned, pulling latest..."
|
| 128 |
+
cd "$COSMOS_DIR" && git pull && cd -
|
| 129 |
+
fi
|
| 130 |
+
|
| 131 |
+
# Install cosmos-rl in the post-training environment
|
| 132 |
+
cd "$COSMOS_DIR/examples/cosmos_rl"
|
| 133 |
+
|
| 134 |
+
if [[ ! -d ".venv" ]]; then
|
| 135 |
+
echo " Creating virtual environment and installing cosmos-rl..."
|
| 136 |
+
# Use uv if available (faster), else pip
|
| 137 |
+
if command -v uv &> /dev/null; then
|
| 138 |
+
uv venv .venv
|
| 139 |
+
source .venv/bin/activate
|
| 140 |
+
uv pip install -e ".[all]"
|
| 141 |
+
else
|
| 142 |
+
python3 -m venv .venv
|
| 143 |
+
source .venv/bin/activate
|
| 144 |
+
pip install -e ".[all]"
|
| 145 |
+
fi
|
| 146 |
+
else
|
| 147 |
+
echo " Virtual environment exists, activating..."
|
| 148 |
+
source .venv/bin/activate
|
| 149 |
+
fi
|
| 150 |
+
|
| 151 |
+
# Install wandb
|
| 152 |
+
pip install wandb --quiet 2>/dev/null || true
|
| 153 |
+
if [[ -n "${WANDB_API_KEY:-}" ]]; then
|
| 154 |
+
wandb login "$WANDB_API_KEY" 2>/dev/null || true
|
| 155 |
+
fi
|
| 156 |
+
|
| 157 |
+
# Install redis (required by cosmos-rl)
|
| 158 |
+
if ! command -v redis-server &> /dev/null; then
|
| 159 |
+
echo " Installing redis-server..."
|
| 160 |
+
sudo apt-get update -qq && sudo apt-get install -y -qq redis-server
|
| 161 |
+
fi
|
| 162 |
+
|
| 163 |
+
echo " Setup complete!"
|
| 164 |
+
|
| 165 |
+
# ============================================================
|
| 166 |
+
# Step 2: Generate training configuration
|
| 167 |
+
# ============================================================
|
| 168 |
+
echo ""
|
| 169 |
+
echo "[Step 2] Generating training configuration..."
|
| 170 |
+
|
| 171 |
+
TRAIN_DIR="$COSMOS_DIR/examples/cosmos_rl/aegis_training"
|
| 172 |
+
mkdir -p "$TRAIN_DIR"
|
| 173 |
+
|
| 174 |
+
# Write the TOML config dynamically based on args
|
| 175 |
+
cat > "$TRAIN_DIR/aegis_sft.toml" << TOML_EOF
|
| 176 |
+
# AEGIS SFT Configuration — Auto-generated
|
| 177 |
+
# Model: $MODEL_NAME | Epochs: $NUM_EPOCHS | LR: $LR
|
| 178 |
+
|
| 179 |
+
[custom.dataset]
|
| 180 |
+
annotation_path = "$DATA_DIR/aegis_llava/annotations_train.json"
|
| 181 |
+
media_path = "$DATA_DIR/"
|
| 182 |
+
|
| 183 |
+
[custom.vision]
|
| 184 |
+
min_pixels = 3136
|
| 185 |
+
max_pixels = 409600
|
| 186 |
+
|
| 187 |
+
[train]
|
| 188 |
+
output_dir = "$OUTPUT_DIR/aegis_sft_${MODEL_SIZE}"
|
| 189 |
+
resume = true
|
| 190 |
+
compile = false
|
| 191 |
+
epoch = $NUM_EPOCHS
|
| 192 |
+
train_batch_per_replica = $BATCH_SIZE
|
| 193 |
+
optm_lr = $LR
|
| 194 |
+
optm_weight_decay = 0.01
|
| 195 |
+
optm_warmup_steps = 0.05
|
| 196 |
+
optm_decay_type = "cosine"
|
| 197 |
+
optm_grad_norm_clip = 1.0
|
| 198 |
+
seed = 42
|
| 199 |
+
|
| 200 |
+
[policy]
|
| 201 |
+
model_name_or_path = "$MODEL_NAME"
|
| 202 |
+
model_max_length = $MAX_LEN
|
| 203 |
+
model_gradient_checkpointing = true
|
| 204 |
+
|
| 205 |
+
[logging]
|
| 206 |
+
logger = ['console', 'wandb']
|
| 207 |
+
project_name = "aegis_reason"
|
| 208 |
+
experiment_name = "sft/aegis_${MODEL_SIZE}_ep${NUM_EPOCHS}_lr${LR}"
|
| 209 |
+
|
| 210 |
+
[train.train_policy]
|
| 211 |
+
type = "sft"
|
| 212 |
+
mini_batch = 4
|
| 213 |
+
dataloader_num_workers = 4
|
| 214 |
+
dataloader_prefetch_factor = 4
|
| 215 |
+
conversation_column_name = "conversations"
|
| 216 |
+
|
| 217 |
+
[train.train_policy.dataset]
|
| 218 |
+
test_size = 0
|
| 219 |
+
|
| 220 |
+
[train.ckpt]
|
| 221 |
+
enable_checkpoint = true
|
| 222 |
+
save_freq = 50
|
| 223 |
+
save_mode = "sync"
|
| 224 |
+
max_keep = 10
|
| 225 |
+
export_safetensors = true
|
| 226 |
+
|
| 227 |
+
[policy.parallelism]
|
| 228 |
+
tp_size = $TP_SIZE
|
| 229 |
+
cp_size = 1
|
| 230 |
+
dp_shard_size = $DP_SIZE
|
| 231 |
+
pp_size = 1
|
| 232 |
+
TOML_EOF
|
| 233 |
+
|
| 234 |
+
echo " Config written to: $TRAIN_DIR/aegis_sft.toml"
|
| 235 |
+
|
| 236 |
+
# Copy the dataloader script
|
| 237 |
+
cp "$DATA_DIR/aegis_dataloader.py" "$TRAIN_DIR/aegis_dataloader.py" 2>/dev/null || \
|
| 238 |
+
cat > "$TRAIN_DIR/aegis_dataloader.py" << 'LOADER_EOF'
|
| 239 |
+
"""AEGIS Custom Dataloader for cosmos-rl SFT — auto-deployed copy."""
|
| 240 |
+
import json, os, logging
|
| 241 |
+
from torch.utils.data import Dataset
|
| 242 |
+
from PIL import Image
|
| 243 |
+
|
| 244 |
+
logger = logging.getLogger(__name__)
|
| 245 |
+
|
| 246 |
+
class CosmosSFTDataset(Dataset):
|
| 247 |
+
def setup(self, config, tokenizer, *args, **kwargs):
|
| 248 |
+
self.config = config
|
| 249 |
+
self.tokenizer = tokenizer
|
| 250 |
+
self.media_path = config.custom.dataset.media_path or ""
|
| 251 |
+
self.min_pixels = getattr(config.custom.vision, 'min_pixels', 3136)
|
| 252 |
+
self.max_pixels = getattr(config.custom.vision, 'max_pixels', 409600)
|
| 253 |
+
annotation_path = config.custom.dataset.annotation_path
|
| 254 |
+
logger.info(f"Loading AEGIS annotations from {annotation_path}")
|
| 255 |
+
with open(annotation_path, 'r') as f:
|
| 256 |
+
self.annotations = json.load(f)
|
| 257 |
+
logger.info(f"Loaded {len(self.annotations)} training samples")
|
| 258 |
+
|
| 259 |
+
def __len__(self):
|
| 260 |
+
return len(self.annotations)
|
| 261 |
+
|
| 262 |
+
def __getitem__(self, idx):
|
| 263 |
+
entry = self.annotations[idx]
|
| 264 |
+
image_rel = entry.get("image", "")
|
| 265 |
+
if self.media_path and not os.path.isabs(image_rel):
|
| 266 |
+
image_path = os.path.join(self.media_path, image_rel)
|
| 267 |
+
else:
|
| 268 |
+
image_path = image_rel
|
| 269 |
+
return {
|
| 270 |
+
"id": entry["id"],
|
| 271 |
+
"image": image_path,
|
| 272 |
+
"conversations": entry["conversations"],
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
dataset = CosmosSFTDataset
|
| 276 |
+
LOADER_EOF
|
| 277 |
+
|
| 278 |
+
echo " Dataloader written to: $TRAIN_DIR/aegis_dataloader.py"
|
| 279 |
+
|
| 280 |
+
# ============================================================
|
| 281 |
+
# Step 3: Launch SFT Training
|
| 282 |
+
# ============================================================
|
| 283 |
+
echo ""
|
| 284 |
+
echo "[Step 3] Launching SFT training..."
|
| 285 |
+
echo " Command: cosmos-rl --config aegis_sft.toml aegis_dataloader.py"
|
| 286 |
+
echo " Output: $OUTPUT_DIR/aegis_sft_${MODEL_SIZE}/"
|
| 287 |
+
echo " Monitor: Check wandb dashboard or output logs"
|
| 288 |
+
echo ""
|
| 289 |
+
echo "============================================================"
|
| 290 |
+
echo " TRAINING START — $(date)"
|
| 291 |
+
echo "============================================================"
|
| 292 |
+
|
| 293 |
+
cd "$TRAIN_DIR"
|
| 294 |
+
cosmos-rl --config aegis_sft.toml aegis_dataloader.py
|
| 295 |
+
|
| 296 |
+
echo ""
|
| 297 |
+
echo "============================================================"
|
| 298 |
+
echo " TRAINING COMPLETE — $(date)"
|
| 299 |
+
echo "============================================================"
|
| 300 |
+
|
| 301 |
+
# Find the latest checkpoint
|
| 302 |
+
CKPT_DIR=$(find "$OUTPUT_DIR/aegis_sft_${MODEL_SIZE}" -name "checkpoints" -type d 2>/dev/null | head -1)
|
| 303 |
+
if [[ -n "$CKPT_DIR" ]]; then
|
| 304 |
+
LATEST_CKPT=$(ls -td "$CKPT_DIR"/step_* 2>/dev/null | head -1)
|
| 305 |
+
echo " Latest checkpoint: $LATEST_CKPT"
|
| 306 |
+
echo ""
|
| 307 |
+
echo " To run inference with the fine-tuned model:"
|
| 308 |
+
echo " python3 aegis_inference.py --checkpoint $LATEST_CKPT --image <path_to_frame.png>"
|
| 309 |
+
else
|
| 310 |
+
echo " WARNING: No checkpoint directory found."
|
| 311 |
+
fi
|
aegis-reason/aegis-reason/scripts/push_to_hub.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Push AEGIS dataset to HuggingFace Hub.
|
| 4 |
+
|
| 5 |
+
Usage:
|
| 6 |
+
# Set HF_TOKEN first
|
| 7 |
+
export HF_TOKEN=hf_xxx
|
| 8 |
+
|
| 9 |
+
# Push dataset
|
| 10 |
+
python push_to_hub.py \
|
| 11 |
+
--dataset-dir aegis_dataset \
|
| 12 |
+
--llava-dir aegis_llava \
|
| 13 |
+
--repo-id <your-username>/aegis-disaster-rescue \
|
| 14 |
+
--private # optional
|
| 15 |
+
|
| 16 |
+
# The script uploads:
|
| 17 |
+
# - sft_data.jsonl (raw SFT records)
|
| 18 |
+
# - annotations_train.json / annotations_val.json (LLaVA format)
|
| 19 |
+
# - topdown/ frames (as tar.gz for efficiency)
|
| 20 |
+
# - egocentric/ frames (as tar.gz)
|
| 21 |
+
# - chains/ ground truth JSONs (as tar.gz)
|
| 22 |
+
# - manifest.json (dataset metadata)
|
| 23 |
+
# - README.md (dataset card)
|
| 24 |
+
"""
|
| 25 |
+
|
| 26 |
+
import argparse
|
| 27 |
+
import os
|
| 28 |
+
import sys
|
| 29 |
+
import tarfile
|
| 30 |
+
import tempfile
|
| 31 |
+
import shutil
|
| 32 |
+
from pathlib import Path
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def create_archive(source_dir: str, archive_path: str, name: str):
|
| 36 |
+
"""Create a tar.gz archive of a directory."""
|
| 37 |
+
print(f" Archiving {name}...")
|
| 38 |
+
with tarfile.open(archive_path, "w:gz") as tar:
|
| 39 |
+
for fn in sorted(os.listdir(source_dir)):
|
| 40 |
+
tar.add(os.path.join(source_dir, fn), arcname=f"{name}/{fn}")
|
| 41 |
+
size_mb = os.path.getsize(archive_path) / (1024 * 1024)
|
| 42 |
+
count = len(os.listdir(source_dir))
|
| 43 |
+
print(f" → {archive_path} ({size_mb:.1f} MB, {count} files)")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def main():
|
| 47 |
+
parser = argparse.ArgumentParser(description="Push AEGIS dataset to HuggingFace Hub")
|
| 48 |
+
parser.add_argument("--dataset-dir", default="aegis_dataset",
|
| 49 |
+
help="Path to AEGIS dataset directory")
|
| 50 |
+
parser.add_argument("--llava-dir", default="aegis_llava",
|
| 51 |
+
help="Path to LLaVA-formatted annotations")
|
| 52 |
+
parser.add_argument("--repo-id", required=True,
|
| 53 |
+
help="HuggingFace repo ID (e.g., username/aegis-disaster-rescue)")
|
| 54 |
+
parser.add_argument("--private", action="store_true",
|
| 55 |
+
help="Create private repo")
|
| 56 |
+
parser.add_argument("--dataset-card", default="hf_dataset_card.md",
|
| 57 |
+
help="Path to dataset card README")
|
| 58 |
+
args = parser.parse_args()
|
| 59 |
+
|
| 60 |
+
try:
|
| 61 |
+
from huggingface_hub import HfApi, create_repo
|
| 62 |
+
except ImportError:
|
| 63 |
+
print("ERROR: huggingface_hub not installed. Run: pip install huggingface_hub")
|
| 64 |
+
sys.exit(1)
|
| 65 |
+
|
| 66 |
+
token = os.environ.get("HF_TOKEN")
|
| 67 |
+
if not token:
|
| 68 |
+
print("ERROR: Set HF_TOKEN environment variable")
|
| 69 |
+
sys.exit(1)
|
| 70 |
+
|
| 71 |
+
api = HfApi(token=token)
|
| 72 |
+
|
| 73 |
+
# Create repo
|
| 74 |
+
print(f"Creating repo: {args.repo_id}")
|
| 75 |
+
try:
|
| 76 |
+
create_repo(
|
| 77 |
+
args.repo_id,
|
| 78 |
+
repo_type="dataset",
|
| 79 |
+
private=args.private,
|
| 80 |
+
token=token,
|
| 81 |
+
exist_ok=True,
|
| 82 |
+
)
|
| 83 |
+
except Exception as e:
|
| 84 |
+
print(f" Repo may already exist: {e}")
|
| 85 |
+
|
| 86 |
+
with tempfile.TemporaryDirectory() as staging:
|
| 87 |
+
print("\nStaging files...")
|
| 88 |
+
|
| 89 |
+
# 1. Copy dataset card as README.md
|
| 90 |
+
if os.path.exists(args.dataset_card):
|
| 91 |
+
shutil.copy(args.dataset_card, os.path.join(staging, "README.md"))
|
| 92 |
+
print(" ✓ README.md (dataset card)")
|
| 93 |
+
|
| 94 |
+
# 2. Copy SFT data
|
| 95 |
+
sft_path = os.path.join(args.dataset_dir, "sft_data.jsonl")
|
| 96 |
+
if os.path.exists(sft_path):
|
| 97 |
+
shutil.copy(sft_path, os.path.join(staging, "sft_data.jsonl"))
|
| 98 |
+
size_mb = os.path.getsize(sft_path) / (1024 * 1024)
|
| 99 |
+
print(f" ✓ sft_data.jsonl ({size_mb:.1f} MB)")
|
| 100 |
+
|
| 101 |
+
# 3. Copy manifest
|
| 102 |
+
manifest_path = os.path.join(args.dataset_dir, "manifest.json")
|
| 103 |
+
if os.path.exists(manifest_path):
|
| 104 |
+
shutil.copy(manifest_path, os.path.join(staging, "manifest.json"))
|
| 105 |
+
print(" ✓ manifest.json")
|
| 106 |
+
|
| 107 |
+
# 4. Copy LLaVA annotations
|
| 108 |
+
for fn in ["annotations_train.json", "annotations_val.json", "conversion_stats.json"]:
|
| 109 |
+
src = os.path.join(args.llava_dir, fn)
|
| 110 |
+
if os.path.exists(src):
|
| 111 |
+
shutil.copy(src, os.path.join(staging, fn))
|
| 112 |
+
size_mb = os.path.getsize(src) / (1024 * 1024)
|
| 113 |
+
print(f" ✓ {fn} ({size_mb:.1f} MB)")
|
| 114 |
+
|
| 115 |
+
# 5. Archive image directories
|
| 116 |
+
for subdir in ["topdown", "egocentric", "chains"]:
|
| 117 |
+
src = os.path.join(args.dataset_dir, subdir)
|
| 118 |
+
if os.path.isdir(src):
|
| 119 |
+
archive = os.path.join(staging, f"{subdir}.tar.gz")
|
| 120 |
+
create_archive(src, archive, subdir)
|
| 121 |
+
|
| 122 |
+
# 6. Upload all staged files
|
| 123 |
+
print(f"\nUploading to {args.repo_id}...")
|
| 124 |
+
api.upload_folder(
|
| 125 |
+
folder_path=staging,
|
| 126 |
+
repo_id=args.repo_id,
|
| 127 |
+
repo_type="dataset",
|
| 128 |
+
commit_message="Upload AEGIS disaster rescue reasoning dataset",
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
print(f"\n✓ Dataset published: https://huggingface.co/datasets/{args.repo_id}")
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
if __name__ == "__main__":
|
| 135 |
+
main()
|