|
Download README.md from NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion: direct link, hf CLI and curl.
- Browser
- Download file 9.63 kB
-
https://huggingface.co/NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion/resolve/main/README.md
- Command line
-
hf download hf://NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion/README.md
-
curl -L -o README.md https://huggingface.co/NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion/resolve/main/README.md
9.63 kB
| language: | |
| - en | |
| base_model: | |
| - GSAI-ML/LLaDA-8B-Base | |
| - GSAI-ML/LLaDA-8B-Instruct | |
| tags: | |
| - pytorch | |
| - masked-diffusion | |
| - llada | |
| - risk-head | |
| - toxicity | |
| - safety | |
| - research | |
| model-index: | |
| - name: Inference-Time-Derisking-in-Masked-Diffusion | |
| results: [] | |
| # Inference-Time-Derisking-in-Masked-Diffusion | |
| Research code and two trained, noise-conditioned linear risk heads for **REDACT — Risk-Evaluated Decoding At Commit-Time**. REDACT evaluates the risk of top-K candidate substitutions during masked diffusion decoding and selects safer candidates along a single generation trajectory. | |
| **Source:** [NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion](https://github.com/NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion), exported from commit [`567e50102f0d9934a8f818fb50970e0484310b24`](https://github.com/NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion/tree/567e50102f0d9934a8f818fb50970e0484310b24). | |
| This repository contains auxiliary risk heads. The LLaDA backbone weights and tokenizers must be obtained separately from their respective repositories. Load the heads with the included research runtime. | |
| ## Released checkpoints | |
| | Task | Backbone association from the source configurations | Recommended checkpoint | | |
| |---|---|---| | |
| | Toxicity control | [GSAI-ML/LLaDA-8B-Base](https://huggingface.co/GSAI-ML/LLaDA-8B-Base) | [`checkpoints/linear_heads/time_dependent_mlp_best.pt`](time_dependent_mlp_best.pt) | | |
| | Refusal-robustness / jailbreak auxiliary risk | [GSAI-ML/LLaDA-8B-Instruct](https://huggingface.co/GSAI-ML/LLaDA-8B-Instruct) | [`checkpoints/linear_jb_aux/time_dependent_linear_best.pt`](time_dependent_linear_best.pt) | | |
| Both heads consume 4,096-dimensional pooled backbone features and use 8 noise bins with a 32-dimensional noise embedding. Each has **4,385 trainable parameters**, a single affine scalar head, and a softplus risk output. Per-bin calibration thresholds are stored in each checkpoint. | |
| The toxicity checkpoint retains its original `time_dependent_mlp_*.pt` filename and `model_family=mlp` metadata. Its `hidden_sizes=[]` configuration makes it a linear head; `linear_head.runtime.load_linear_checkpoint` explicitly supports this legacy format. The auxiliary checkpoint uses the native `time_dependent_linear` format. No weight conversion or renaming was performed. | |
| Each checkpoint directory includes the supplied `best` and `last` weights, resolved training configuration, training metrics, logs, and Hydra configuration history. The auxiliary directory also includes its original acceptance and error-correlation reports. These records retain historical training-machine paths; the paths are provenance, not runtime requirements. | |
| The upstream code also supports Dream and other risk-head families. No Dream, polytope, or JB reward-model checkpoint is included in this release. | |
| ## Download and environment | |
| ```bash | |
| pip install -U huggingface_hub | |
| hf download NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion \ | |
| --local-dir Inference-Time-Derisking-in-Masked-Diffusion | |
| cd Inference-Time-Derisking-in-Masked-Diffusion | |
| python -m zipfile -e Inference-Time-Derisking-in-Masked-Diffusion-hf-release.zip . | |
| ``` | |
| The complete upstream source and original checkpoint directories are included in [`Inference-Time-Derisking-in-Masked-Diffusion-hf-release.zip`](Inference-Time-Derisking-in-Masked-Diffusion-hf-release.zip). Extract the bundle into the download directory before running the examples below. The four original `.pt` weight files are also available individually at the Hub repository root. The original documentation is preserved in [`UPSTREAM_README.md`](UPSTREAM_README.md). | |
| The upstream environment targets **Linux, Python >=3.12, and CUDA 13.0 on Hopper/H200 hardware**. With `uv` available: | |
| ```bash | |
| uv sync --extra cu130 | |
| source .venv/bin/activate | |
| ``` | |
| A bare `uv sync` deliberately does not install PyTorch. The CUDA extra includes heavy dependencies, including a source build of flash-attn. Consult the upstream documentation and `pyproject.toml` for the supported environment. | |
| ## Use the toxicity head with REDACT | |
| Run from the repository root after configuring the required backbone and evaluation data: | |
| ```bash | |
| python main.py safety_eval --config-name linear \ | |
| control.method=redact \ | |
| control.risk_model_type=linear \ | |
| control.risk_checkpoint=checkpoints/linear_heads/time_dependent_mlp_best.pt \ | |
| control.eta=1e8 \ | |
| control.exact_dr_topk=4 \ | |
| data.local_prompts=null data.num_samples=4 \ | |
| eval.ppl=false eval.degeneracy=false eval.llm_judge.enabled=false \ | |
| eval.output_dir=output/hf_toxicity_smoke | |
| ``` | |
| This example is a small usage smoke, not a reproduction of the paper's selected evaluation set. The generic safety-evaluation preset defaults to the polytope compatibility path; select the linear preset and checkpoint explicitly as above. Disabling the optional heavy evaluators avoids loading them; the backbone and configured toxicity scorer are still needed. | |
| ## Use the auxiliary head | |
| ```bash | |
| python main.py safety_eval --config-name jailbreak \ | |
| control.method=redact \ | |
| control.risk_model_type=linear \ | |
| control.risk_checkpoint=checkpoints/linear_jb_aux/time_dependent_linear_best.pt \ | |
| control.eta=10000 control.exact_dr_topk=4 \ | |
| data.num_samples=4 \ | |
| eval.ppl=false eval.degeneracy=false eval.llm_judge.enabled=false \ | |
| eval.output_dir=output/hf_jailbreak_smoke | |
| ``` | |
| This configuration uses the instruct backbone and the jailbreak evaluation pipeline, including its configured safety scorer. It is a usage example, not the frozen 616-prompt confirmatory study. That study additionally requires the frozen prompt cache referenced by `scripts/jailbreak/disjoint_confirmatory.sh`, which is not included here. | |
| For direct integration with already pooled features: | |
| ```python | |
| import torch | |
| from linear_head.runtime import load_linear_checkpoint | |
| head, encoder = load_linear_checkpoint( | |
| "checkpoints/linear_heads/time_dependent_mlp_best.pt", | |
| device=torch.device("cpu"), | |
| ) | |
| assert encoder is None | |
| # features: [batch, 4096] pooled hidden states from the matching backbone. | |
| # rho_idx: [batch] integer noise-bin indices in [0, 7]. | |
| # Follow the source runtime's pooling and binning conventions. | |
| with torch.no_grad(): | |
| outputs = head(features, rho_idx) | |
| risk = outputs["risk"] | |
| ``` | |
| ## Training records and validation | |
| | Recommended checkpoint | Selected epoch recorded in checkpoint | Stored best `macro_fpr_at_tpr` | Calibration target TPR | | |
| |---|---:|---:|---:| | |
| | Toxicity `best` | 23 | 0.08425052894968464 | 0.95 | | |
| | Jailbreak auxiliary `best` | 59 | 0.4659909575577295 | 0.95 | | |
| These are stored training/validation selection records. They use different task caches and should be interpreted within their own tasks. They are not new end-to-end generation measurements or attack success rates. | |
| Release preparation verified archive CRCs, checkpoint tensor shapes, finite model weights, parameter counts, and the auxiliary best-checkpoint SHA-256 against the supplied acceptance report. GPU generation and the paper's evaluation suite were not run during packaging. Full checkpoint metadata, thresholds, and hashes are in [`checkpoint_index.json`](checkpoint_index.json). | |
| ## Bundle layout and provenance | |
| The following tree describes the **extracted release bundle**. The Hub additionally exposes the four weight files, two resolved training configurations, metadata, and this model card directly. The Hub `SHA256SUMS` verifies the uploaded files; the bundle contains its own integrity manifest for the extracted tree. | |
| ```text | |
| README.md Hugging Face model card and release usage | |
| UPSTREAM_README.md Original GitHub documentation | |
| LICENSE Original upstream source-code license | |
| generate.py, main.py, ... Complete upstream tracked source and research assets | |
| linear_head/ Native and legacy-compatible linear-head runtime | |
| checkpoints/ | |
| linear_heads/ Toxicity head and original training records | |
| linear_jb_aux/ Auxiliary head and original training/audit records | |
| checkpoint_index.json Checkpoint metadata, shapes, thresholds, SHA-256 | |
| source_revision.json Pinned source revision and original archive hashes | |
| SHA256SUMS Integrity manifest for every other release file | |
| ``` | |
| Weights and training records were extracted byte-for-byte from the supplied `linear_heads.zip` and `linear_jailbreak_aux.zip`. The original archives remain unchanged outside this release. The release adds documentation, provenance, and integrity files; upstream executable code is preserved. | |
| ## Intended use, limitations, and licensing | |
| Intended for research on inference-time risk control and evaluation of masked diffusion language models. A risk score is a learned proxy and does not guarantee safe, accurate, or appropriate generated text. Behavior depends on the backbone, pooling, noise schedule, decoding configuration, and evaluation distribution. | |
| The upstream **source code** is distributed under its included [MIT license](LICENSE). The supplied checkpoint archives do not specify a separate checkpoint license. This model card does not assign a new license to those weights. Backbone models and third-party datasets remain subject to their own terms. | |
| For method details, reproduction scripts, and further documentation, see the [source repository](https://github.com/NYCU-MLLab/Inference-Time-Derisking-in-Masked-Diffusion) and [`UPSTREAM_README.md`](UPSTREAM_README.md). | |