Repository navigation
fix(evaluation): redact non-public model identities in execution evidence #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d938dfb
13597c3
3a3202c
c481674
c7fe0c5
e7a0bc7
9961e3e
6abcb46
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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): | ||
|
|
@@ -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 | ||
|
|
||
|
|
||
|
|
@@ -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 | ||
|
|
@@ -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, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 3a3202c: |
||
| '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}, | ||
|
|
@@ -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, | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_direquals, is inside, or containsexecution_evidence_dir(also caught via..paths). Separate sibling directories still work. README updated for both.There was a problem hiding this comment.
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_executionwrites using the original strings. Withexecution_evidence_dir="."andexecution_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.There was a problem hiding this comment.
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.