Skip to content
Open
13 changes: 13 additions & 0 deletions .agents/skills/evaluation/cosmos3/reasoner/vlmevalkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ or return API. Evidence requests raw token IDs but retains only visual groups,
actual response model, usage and finish reasons—not prompts, text token IDs,
labels, media, endpoint URLs or credentials.

Model identities are redacted by default. Model names (requested, returned, or in
an operator processor profile) are recorded only if they are on the public
allowlist (`nvidia/Cosmos3-Nano`), extended with exact names in the
comma-separated `COSMOS_EVIDENCE_PUBLIC_MODELS`. Only approve names that are
already public. Revisions are recorded only as commit hashes or `unknown`. Any
other value, such as a local checkpoint path, internal model name, branch or tag,
is recorded as `redacted`. `aggregate_execution_records` applies the same policy
again, so records saved by older versions or under a different allowlist are
redacted under the current one. To debug, set `execution_identity_dir` to a
separate directory: it receives the unredacted identities per response. It must
not be the evidence directory, inside it, or contain it; the constructor rejects
that. That output is not sanitized; never share it alongside the evidence.

Nano's explicit processor profile comes from the pinned public
[`config.json`](https://huggingface.co/nvidia/Cosmos3-Nano/resolve/e59a53c25979a090fa8706c9acc0c254a6e89b92/config.json)
and [`preprocessor_config.json`](https://huggingface.co/nvidia/Cosmos3-Nano/resolve/e59a53c25979a090fa8706c9acc0c254a6e89b92/preprocessor_config.json):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,19 @@ def __init__(self,
# Generic payload passthrough for vLLM-specific fields (e.g. structured_outputs).
self.extra_body = kwargs.pop('extra_body', None)
# Opt-in; never forward evidence configuration to BaseAPI or the endpoint.
self.execution_evidence_dir = kwargs.pop('execution_evidence_dir', None)
# Both directories are resolved once (~ expanded, absolute) and those exact paths are
# used for the overlap check and every write, so the check matches where files land.
from pathlib import Path
resolve = lambda path: None if path is None else Path(path).expanduser().resolve()
self.execution_evidence_dir = resolve(kwargs.pop('execution_evidence_dir', None))
self.execution_processor_profile = kwargs.pop('execution_processor_profile', None)
# Separate opt-in directory for unredacted model identities; never share it.
self.execution_identity_dir = resolve(kwargs.pop('execution_identity_dir', None))
if self.execution_evidence_dir is not None and self.execution_identity_dir is not None:
evidence, identity = self.execution_evidence_dir, self.execution_identity_dir
# Sharing either tree must never include the other's files.
if evidence == identity or evidence in identity.parents or identity in evidence.parents:
raise ValueError('execution_identity_dir must not be, contain, or be inside execution_evidence_dir')
self._last_execution_record = None
# Default Qwen3 / Reason2 setup.
self.image_patch_size = kwargs.pop('image_patch_size', None)
Expand Down Expand Up @@ -540,20 +551,23 @@ def prepare_inputs(self, inputs):
def _record_execution(self, payload, raw, media=None):
if self.execution_evidence_dir is None:
return
from pathlib import Path
import tempfile
from vlmeval.execution_evidence import build_execution_record
from vlmeval.execution_evidence import build_execution_record, private_identity_record

revision = os.environ.get("COSMOS_MODEL_REVISION", "unknown")
record = build_execution_record(payload, raw, media=media,
processor_profile=self.execution_processor_profile,
requested_model_revision=os.environ.get("COSMOS_MODEL_REVISION", "unknown"))
directory = Path(self.execution_evidence_dir)
directory.mkdir(parents=True, exist_ok=True, mode=0o700)
# O_EXCL + mode 0600 from mkstemp, unique across processes/threads/retries.
fd, path = tempfile.mkstemp(prefix='response-', suffix='.json', dir=directory)
with os.fdopen(fd, 'w') as output:
json.dump(record, output, allow_nan=False)
output.write('\n')
requested_model_revision=revision)
writes = [(self.execution_evidence_dir, record)]
if self.execution_identity_dir is not None:
writes.append((self.execution_identity_dir, private_identity_record(payload, raw, revision)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional hardening: when I configured both output directories to the same temporary directory, it contained two response JSONs, one with the original model name. A private directory nested under the evidence directory would also be included when that tree is shared. Consider resolving both paths and rejecting overlapping directories before writing either file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done too: the constructor resolves both paths and raises if execution_identity_dir equals, is inside, or contains execution_evidence_dir (also caught via .. paths). Separate sibling directories still work. README updated for both.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One remaining case on c481674: the constructor checks the expanded, absolute paths, but _record_execution writes using the original strings. With execution_evidence_dir="." and execution_identity_dir="~/private" in a working directory outside home, validation sees two separate directories. At write time, Path(target) treats ~ as a literal directory name, so the unredacted file lands under ./~/private/ inside the evidence tree. Please store the two resolved paths on the instance after validation and use those same paths for both writes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed in c7fe0c5. Both directories are now expanded and resolved once in the constructor and stored on the instance; the overlap check and both writes use those same paths. Checked your case (evidence ., identity ~/private, cwd outside home): no literal ./~ is created, the private file lands in the real ~/private, and nothing with the original model path appears under the evidence tree. Overlaps written via ~, ./ or an absolute path to the same place are still rejected; sibling directories still work.

for directory, content in writes:
directory.mkdir(parents=True, exist_ok=True, mode=0o700)
# O_EXCL + mode 0600 from mkstemp, unique across processes/threads/retries.
fd, path = tempfile.mkstemp(prefix='response-', suffix='.json', dir=directory)
with os.fdopen(fd, 'w') as output:
json.dump(content, output, allow_nan=False)
output.write('\n')
self._last_execution_record = record

def generate_inner(self, inputs, **kwargs) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,37 @@
}


def _identity(value):
return value if isinstance(value, str) and re.fullmatch(r'[A-Za-z0-9_./+:-]{1,240}', value) and '://' not in value else None
# Model names are recorded only when publicly approved; anything else (local
# checkpoint paths, internal names) becomes REDACTED. Approve more public names
# with COSMOS_EVIDENCE_PUBLIC_MODELS (comma-separated, exact match).
PUBLIC_MODELS = frozenset({'nvidia/Cosmos3-Nano'})
REDACTED = 'redacted'


def public_models():
extra = os.environ.get('COSMOS_EVIDENCE_PUBLIC_MODELS', '')
return PUBLIC_MODELS | {name.strip() for name in extra.split(',') if name.strip()}


def _model_identity(value):
if not isinstance(value, str) or not value:
return None
return value if value in public_models() else REDACTED


def _revision_identity(value):
"""Commit hashes and 'unknown' only; branch names, tags and paths are redacted."""
if not isinstance(value, str) or not value:
return None
return value if value == 'unknown' or re.fullmatch(r'[0-9a-f]{7,64}', value) else REDACTED


def private_identity_record(payload: dict, response_json: dict, requested_model_revision=None) -> dict:
"""Unredacted model identities for local debugging. NOT sanitized; never share it."""
raw = response_json if isinstance(response_json, dict) else {}
return {'format_version': 1, 'sanitized': False,
'requested_model': payload.get('model'), 'requested_model_revision': requested_model_revision,
'observed_model': raw.get('model')}


def _number(value):
Expand Down Expand Up @@ -89,9 +118,10 @@ def _profile(value):
sources=[f'https://huggingface.co/nvidia/Cosmos3-Nano/resolve/{NANO_REVISION}/{name}'
for name in ('config.json', 'preprocessor_config.json')])
else:
for key in ('profile_model', 'profile_revision'):
if _identity(value.get(key)):
result[key] = value[key]
if value.get('profile_model') is not None:
result['profile_model'] = _model_identity(value['profile_model'])
if value.get('profile_revision') is not None:
result['profile_revision'] = _revision_identity(value['profile_revision'])
return result


Expand Down Expand Up @@ -151,7 +181,7 @@ def build_execution_record(payload: dict, response_json: dict, *, media=None, pr
isinstance(choice.get('message'), dict) and 'content' in choice['message'] and
(choice['message']['content'] is None or isinstance(choice['message']['content'], str))
for choice in choices))
observed = {'response_valid': bool(valid), 'model': _identity(raw.get('model')),
observed = {'response_valid': bool(valid), 'model': _model_identity(raw.get('model')),
'usage': _knobs(raw.get('usage'), ('prompt_tokens', 'completion_tokens', 'total_tokens')),
'finish_reasons': [choice.get('finish_reason') if isinstance(choice, dict) and
choice.get('finish_reason') in ('stop', 'length', 'error', 'content_filter') else None
Expand Down Expand Up @@ -202,8 +232,8 @@ def build_execution_record(payload: dict, response_json: dict, *, media=None, pr
status = ('failed_response' if not valid else 'mismatch' if 'mismatch' in checks.values() else
'verified_under_explicit_profile' if all(checks[key] == 'match' for key in required) else 'unknown')
return {'format_version': 1,
'requested': {'model': _identity(payload.get('model')), 'generation': generation,
'model_revision': _identity(requested_model_revision),
'requested': {'model': _model_identity(payload.get('model')), 'generation': generation,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please apply the same identity filters inside aggregate_execution_records before building observed_models and grouping requested_settings. I passed a record produced by the base revision to the new aggregator. Both the synthetic non-public model name and its branch revision appeared verbatim in the summary, with debugging disabled. Re-sanitizing a copy of requested.model, requested.model_revision and observed.model at aggregation time would also honor the operator’s current allowlist when older records are reused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 3a3202c: aggregate_execution_records now re-applies the identity policy to a copy of each record before building observed_models and requested_settings, so it uses the current allowlist. Checked with a record built by the base revision (non-public name + branch revision): both come out redacted in the summary, the caller's record isn't mutated, and Nano's aggregate is unchanged.

'model_revision': _revision_identity(requested_model_revision),
'mm_processor_kwargs': processor, 'media_io_kwargs': io,
'chat_template_kwargs': _knobs(payload.get('chat_template_kwargs'), ('enable_thinking',)),
'image_inputs': images, 'video_inputs': videos, 'media': requested_media},
Expand All @@ -218,8 +248,19 @@ def build_execution_record(payload: dict, response_json: dict, *, media=None, pr
'generation settings and model revision are requested/configured, not server-attested']}}


def _sanitized(record):
"""Copy with identities re-filtered under the current policy (older or reused records)."""
requested = dict(record['requested'])
if 'model' in requested:
requested['model'] = _model_identity(requested['model'])
if 'model_revision' in requested:
requested['model_revision'] = _revision_identity(requested['model_revision'])
observed = dict(record['observed'], model=_model_identity(record['observed'].get('model')))
return dict(record, requested=requested, observed=observed)


def aggregate_execution_records(records, expected_requests=None):
records = [record for record in records if isinstance(record, dict) and
records = [_sanitized(record) for record in records if isinstance(record, dict) and
isinstance(record.get('requested'), dict) and isinstance(record.get('observed'), dict)]
counts = Counter(record.get('verification', {}).get('status', 'unknown') for record in records)
return {'requests_recorded': len(records), 'expected_requests': expected_requests,
Expand Down