Run this model with HF Jobs

Run xiahao90/laya-vulnerabilit on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs to fine-tune https://huggingface.co/xiahao90/laya-vulnerabilit. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/xiahao90/laya-vulnerabilit on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
xiahao90's picture
发布 Laya 漏洞检测实验模型、Apache-2.0 许可及复现记录
c4cdb6d verified
Raw History Blame Contribute Delete
5.92 kB
"""Prepare a local release candidate, without publishing or including optimizer state."""
import argparse
import json
import shutil
from pathlib import Path
from .fetch import ROOT, sha256
def package(model, destination):
run = model / "run"
config = json.loads((run / "config.json").read_text())
metrics = json.loads((run / "metrics.json").read_text())
if not metrics.get("reload_verified") or sha256(model / "model.safetensors") != metrics["checkpoint_sha256"]:
raise ValueError("Checkpoint has not passed reload verification or does not match the recorded hash")
destination.mkdir(parents=True, exist_ok=True)
for name in ("model.safetensors", "rl_agent_config.json", "README.md"):
shutil.copy2(model / name, destination / name)
for name in ("BASE_MODEL_README.md", "LICENSE", "NOTICE"):
if (model / name).exists():
shutil.copy2(model / name, destination / name)
for name in ("encoder", "tokenizer", "source-notices"):
shutil.copytree(model / name, destination / name, dirs_exist_ok=True)
evidence = destination / "training-records"
evidence.mkdir(exist_ok=True)
for name in ("config.json", "metrics.json", "baseline.json", "best_epoch.json", "weight-audit.json", "events.jsonl", "training-scope.json", "selection-provenance.jsonl", "selection-provenance-summary.json"):
if (run / name).exists():
shutil.copy2(run / name, evidence / name)
for path in run.glob("external-*.json"):
shutil.copy2(path, evidence / path.name)
# Only the known Apache-licensed, generated BenchProctor selection is prepared for redistribution.
# Mixed third-party datasets require their own review; never export those automatically.
rows = {s: [json.loads(line) for line in (run / f"{s}_selection.jsonl").open()] for s in ("train", "valid", "test")}
export_data = all(r["source"] == "benchproctor" and r["license"] == "Apache-2.0" for rs in rows.values() for r in rs)
if export_data:
data = destination / "training-data"
data.mkdir(exist_ok=True)
for split in rows:
shutil.copy2(run / f"{split}_selection.jsonl", data / f"{split}.jsonl")
summary = {"schema_version": 1, "description": "Exact samples actually used in this experiment, in original order; not the complete upstream corpus.",
"source": "https://github.com/TheAuditorTool/BenchProctor", "license": "Apache-2.0",
"split_counts": {s: len(rs) for s, rs in rows.items()},
"files": {s: {"sha256": sha256(data / f"{s}.jsonl"), "bytes": (data / f"{s}.jsonl").stat().st_size} for s in rows}}
(data / "summary.json").write_text(json.dumps(summary, indent=2))
shutil.copytree(ROOT / "training", destination / "training", dirs_exist_ok=True,
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"))
recipe = {"method": "supervised_cross_entropy", "base_sha256": config["base_sha256"],
"mode": config["mode"], "tail_layers": config.get("tail_layers", 0), "epochs": config["epochs"],
"max_len": config["max_len"], "head_max_len": config["head_max_len"], "batch_size": config["batch_size"],
"learning_rate": config["learning_rate"], "seed": config["seed"], "max_fpr": config["max_fpr"],
"sample_order": "Use --train-limit 0 --eval-limit 0 --preserve-data-order with training-data/.",
"device": config.get("actual_device", config["device"]),
"limits": "Seeds and versions permit experiment reproduction; bit-identical weights across devices/backends are not promised."}
(destination / "reproduction-recipe.json").write_text(json.dumps(recipe, indent=2))
command = ("python -m training.finetune --base /path/to/original/laya --data training-data "
"--output reproduced-model --train-limit 0 --eval-limit 0 --preserve-data-order "
f"--mode {recipe['mode']} --tail-layers {recipe['tail_layers']} --device {recipe['device']} "
f"--epochs {recipe['epochs']} --max-len {recipe['max_len']} --head-max-len {recipe['head_max_len']} "
f"--batch-size {recipe['batch_size']} --learning-rate {recipe['learning_rate']} --seed {recipe['seed']} "
f"--max-fpr {recipe['max_fpr']} --expected-base-sha256 {recipe['base_sha256']}")
(destination / "REPRODUCE.md").write_text("# Reproduce this experiment\n\nInstall the pinned dependencies in `training/requirements-training.txt`, supply the matching original base checkpoint, and run from this directory:\n\n```bash\n" + command + "\n```\n\nOnly the exact generated BenchProctor selection is included. Keep `source-notices/` and the base-model attribution. This is a local review candidate, not a published release or a production scanner.\n")
inventory = {str(p.relative_to(destination)): {"sha256": sha256(p), "bytes": p.stat().st_size}
for p in sorted(destination.rglob("*")) if p.is_file() and p.name != "release-inventory.json"}
if inventory["model.safetensors"]["sha256"] != metrics["checkpoint_sha256"]:
raise ValueError("Packaged checkpoint differs from the evaluated checkpoint")
(destination / "release-inventory.json").write_text(json.dumps({"status": "local_review_candidate_not_published", "exact_training_data_included": export_data,
"checkpoint_sha256": metrics["checkpoint_sha256"], "files": inventory}, indent=2))
print(destination)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--model", type=Path, default=ROOT / "artifacts/laya-vulnerability")
parser.add_argument("--destination", type=Path, default=ROOT / "artifacts/release/laya-vulnerability")
args = parser.parse_args()
package(args.model, args.destination)