Run this model with HF Jobs

Run PRiyanshu0-1/DPDP-SSense 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 and TRL to fine-tune https://huggingface.co/PRiyanshu0-1/DPDP-SSense. 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/PRiyanshu0-1/DPDP-SSense 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.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/PRiyanshu0-1/DPDP-SSense. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
File size: 8,444 Bytes
1f52672
 
e979960
1f52672
e979960
 
1f52672
e979960
 
 
 
 
 
1f52672
 
e979960
 
 
1f52672
e979960
1f52672
 
 
e979960
1f52672
e979960
 
 
 
 
 
 
 
 
 
 
 
1f52672
e979960
 
1f52672
 
e979960
 
 
 
1f52672
e979960
 
1f52672
e979960
 
 
 
 
 
1f52672
e979960
 
 
 
 
 
1f52672
e979960
 
 
1f52672
e979960
 
1f52672
e979960
 
1f52672
e979960
 
 
 
1f52672
e979960
 
 
1f52672
 
 
e979960
1f52672
 
 
 
e979960
1f52672
e979960
 
 
 
 
1f52672
e979960
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1f52672
e979960
 
 
 
 
 
 
1f52672
 
e979960
1f52672
e979960
 
1f52672
e979960
 
 
 
 
 
 
 
1f52672
e979960
 
1f52672
e979960
 
 
 
 
 
1f52672
 
 
e979960
 
1f52672
e979960
1f52672
e979960
 
1f52672
 
e979960
 
 
 
 
 
 
1f52672
 
 
 
e979960
1f52672
e979960
1f52672
e979960
1f52672
e979960
1f52672
 
e979960
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env python3
"""
path_resolver.py – Deterministic POSIX Path Resolution for DPDP Eval Suite (Linux/DGX)

Resolves relative paths consistently across arbitrary Linux working directories
(repo root, ml/, ml/evals/, ml/scripts/, or Docker mount points).

Hierarchy for resolving models & assets:
1. Direct Path relative to current process CWD.
2. Relative to `ml/evals/` (supports legacy `../models/...` args).
3. Relative to `ml/` root directory.
4. Relative to overall project root.
5. Direct lookup in `ml/models/<basename>`.
"""

import os
import sys
import json
from pathlib import Path
from typing import Optional, List, Union


# ═══════════════════════════════════════════════════════════════════════════
# DYNAMIC POSIX ROOT DISCOVERY
# ═══════════════════════════════════════════════════════════════════════════
def _discover_ml_root() -> Path:
    """
    Climbs the filesystem hierarchy from this file's realpath to locate `ml/`.
    Guarantees correct anchoring regardless of Linux symlinks or shell CWD.
    """
    current = Path(__file__).resolve().parent
    while current != current.parent:
        if (current / "data-forge").is_dir() and (current / "evals").is_dir():
            return current
        if (current / "ml" / "data-forge").is_dir():
            return (current / "ml").resolve()
        current = current.parent

    # Standard POSIX fallback
    return Path(__file__).resolve().parent.parent


_ML_DIR = _discover_ml_root()
_EVALS_DIR = (_ML_DIR / "evals").resolve()
_PROJECT_ROOT = _ML_DIR.parent.resolve()


class Paths:
    """Single source of truth for all paths in the DPDP evaluation pipeline."""

    # ── Directory Anchors ───────────────────────────────────────────────
    PROJECT_ROOT: Path = _PROJECT_ROOT
    ML_DIR: Path = _ML_DIR
    EVALS_DIR: Path = _EVALS_DIR
    CORE_DIR: Path = _EVALS_DIR
    SUITES_DIR: Path = _EVALS_DIR / "suites"

    # ── Benchmark Datasets ──────────────────────────────────────────────
    BENCHMARKS_DIR: Path = _EVALS_DIR / "benchmarks"
    CHATBOT_QA_BENCHMARK: Path = BENCHMARKS_DIR / "dpdp_chatbot_qa.json"
    RAG_TESTSET: Path = BENCHMARKS_DIR / "dpdp_rag_testset.json"
    REDTEAM_PROMPTS: Path = BENCHMARKS_DIR / "redteam_hallucination_prompts.json"
    SECURITY_SUITE: Path = BENCHMARKS_DIR / "security_adversarial_suite.json"

    # ── Ground Truth Policies ───────────────────────────────────────────
    HOLDOUT_DIR: Path = _EVALS_DIR / "holdout_policies"
    GROUND_TRUTH: Path = HOLDOUT_DIR / "ground_truth.json"

    # ── Output Reports ──────────────────────────────────────────────────
    REPORTS_DIR: Path = _EVALS_DIR / "reports"

    # ── Schema Contracts ────────────────────────────────────────────────
    SCHEMA_PATH: Path = _PROJECT_ROOT / "libs" / "contracts" / "schemas" / "dpdp_schema.json"

    # ── Knowledge Base & Vector Store ───────────────────────────────────
    DATA_FORGE_DIR: Path = _ML_DIR / "data-forge"
    LAW_TEXT: Path = DATA_FORGE_DIR / "dpdp_act_and_rules_2025.txt"
    HYBRID_INDEX: Path = DATA_FORGE_DIR / "dpdp_hybrid_index.pkl"

    # ── Models & Training Data ──────────────────────────────────────────
    MODELS_DIR: Path = _ML_DIR / "models"
    TRAINING_DATA_DIR: Path = _ML_DIR / "slm-training" / "data"

    @classmethod
    def ensure_reports_dir(cls) -> Path:
        """Ensures the reports directory exists with standard Linux permissions."""
        cls.REPORTS_DIR.mkdir(parents=True, exist_ok=True)
        return cls.REPORTS_DIR

    @classmethod
    def resolve_model_path(cls, model_arg: Optional[Union[str, Path]], default_name: str) -> Path:
        """
        Resolves model paths across Linux environments using multi-tier fallback.
        
        Args:
            model_arg: User/CLI argument (e.g. '../models/audit-model-final' or 'audit-model-final')
            default_name: Default subdirectory under ml/models/ if model_arg is None
        """
        target = str(model_arg).strip() if model_arg else default_name

        # If it's already an absolute path and exists, return immediately
        p = Path(target)
        if p.is_absolute() and p.exists():
            return p.resolve()

        # Search candidates in strict order of resolution
        search_candidates = [
            # 1. Relative to CWD
            (Path.cwd() / target).resolve(),
            # 2. Relative to ml/evals (supports legacy ../models/... calls)
            (cls.EVALS_DIR / target).resolve(),
            # 3. Relative to ml/ root
            (cls.ML_DIR / target).resolve(),
            # 4. Relative to project root
            (cls.PROJECT_ROOT / target).resolve(),
            # 5. Direct lookup in ml/models by target or basename
            (cls.MODELS_DIR / target).resolve(),
            (cls.MODELS_DIR / Path(target).name).resolve(),
        ]

        for candidate in search_candidates:
            if candidate.exists():
                return candidate

        # Return default target under models dir if not found (downstream will report missing path)
        return (cls.MODELS_DIR / Path(target).name).resolve()

    @classmethod
    def resolve_gguf_path(cls, dir_or_file: Union[str, Path]) -> Path:
        """
        Auto-discovers .gguf quantized model files in Linux directories.
        Prioritizes Q4_K_M if multiple quantization formats exist.
        """
        resolved_path = cls.resolve_model_path(dir_or_file, "chatbot-model-final-gguf")

        if resolved_path.is_file() and resolved_path.suffix.lower() == ".gguf":
            return resolved_path

        if resolved_path.is_dir():
            ggufs = sorted(resolved_path.glob("*.gguf"))
            if not ggufs:
                raise FileNotFoundError(
                    f"❌ No .gguf model files located in: {resolved_path}\n"
                    f"Ensure model export completed successfully."
                )

            # Prioritize standard Q4_K_M quantization
            q4_candidates = [g for g in ggufs if "Q4_K_M" in g.name.upper()]
            if len(q4_candidates) == 1:
                return q4_candidates[0].resolve()

            if len(ggufs) > 1:
                names = [g.name for g in ggufs]
                raise ValueError(
                    f"⚠️ Multiple GGUF binaries found in {resolved_path}: {names}\n"
                    f"Specify the exact file path."
                )

            return ggufs[0].resolve()

        raise FileNotFoundError(f"❌ Model path does not exist on Linux host: {resolved_path}")

    @classmethod
    def read_model_label(cls, model_path: Union[str, Path], fallback: str = "Qwen2.5-7B-SLM") -> str:
        """Extracts model metadata dynamically from HuggingFace config.json on Linux."""
        target_dir = cls.resolve_model_path(model_path, "")
        if target_dir.is_file():
            target_dir = target_dir.parent

        config_path = target_dir / "config.json"
        if config_path.exists():
            try:
                with open(config_path, "r", encoding="utf-8") as f:
                    config = json.load(f)

                for key in ["_name_or_path", "model_type", "architectures"]:
                    if key in config and config[key]:
                        val = config[key]
                        if isinstance(val, list) and len(val) > 0:
                            val = val[0]
                        return str(val)
            except Exception:
                pass

        return Path(model_path).name if model_path else fallback