devankit7873 commited on
Commit
0c4b9e8
·
verified ·
1 Parent(s): 8fc7972

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +18 -71
README.md CHANGED
@@ -92,81 +92,28 @@ Evaluated against the official **[JevBench](https://jevbench.github.io/)** test
92
 
93
  ---
94
 
95
- ## 🚀 Quickstart: Direct Inference from Hugging Face
96
 
97
- ### 1. Installation
98
- ```bash
99
- pip install torch transformers safetensors huggingface_hub
100
- ```
101
-
102
- ### 2. Standalone Inference Code
103
  ```python
104
- import os
105
- import torch
106
- import torch.nn as nn
107
- import torch.nn.functional as F
108
- from transformers import AutoTokenizer, AutoModelForCausalLM
109
- from safetensors.torch import load_file
110
- from huggingface_hub import hf_hub_download
111
-
112
- class DecisionHead(nn.Module):
113
- def __init__(self, hidden_size: int = 1536, intermediate_size: int = 512, max_choices: int = 10, dropout: float = 0.1):
114
- super().__init__()
115
- self.max_choices = max_choices
116
- self.norm = nn.LayerNorm(hidden_size)
117
- self.dense = nn.Linear(hidden_size, intermediate_size)
118
- self.act = nn.GELU()
119
- self.dropout = nn.Dropout(dropout)
120
- self.out_proj = nn.Linear(intermediate_size, max_choices)
121
- self.score_proj = nn.Linear(intermediate_size, 1)
122
-
123
- def forward(self, x: torch.Tensor, num_choices: torch.Tensor = None) -> torch.Tensor:
124
- h = self.dropout(self.act(self.dense(self.norm(x))))
125
- logits = self.out_proj(h)
126
- if num_choices is not None:
127
- mask = torch.arange(self.max_choices, device=logits.device).unsqueeze(0) >= num_choices.unsqueeze(1)
128
- logits = logits.masked_fill(mask, -1e4)
129
- return logits
130
-
131
- # 1. Load model & weights
132
- model_id = "devankit7873/QJev-1.5B"
133
- device = "cuda" if torch.cuda.is_available() else "cpu"
134
-
135
- tokenizer = AutoTokenizer.from_pretrained(model_id)
136
- backbone = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, device_map=device)
137
- head = DecisionHead().to(device=device, dtype=torch.bfloat16)
138
-
139
- head_path = hf_hub_download(repo_id=model_id, filename="decision_head.safetensors")
140
- head.load_state_dict(load_file(head_path))
141
- head.eval()
142
-
143
- # 2. Formulate Prompt & Query
144
- context = "Production database primary replica CPU spiked to 100% and connection pool is exhausted with 5,000 waiting queries."
145
- choices = [
146
- "Trigger immediate automated failover to standby replica",
147
- "Restart the primary database daemon immediately",
148
- "Double connection pool limits without scaling compute",
149
- "Silence alerts and monitor for next 15 minutes"
150
- ]
151
-
152
- opts_str = "\n".join([f"[{i+1}] {c}" for i, c in enumerate(choices)])
153
- prompt = (
154
- "<|im_start|>system\n"
155
- "You are an expert decision engine. Evaluate the context and select the optimal decision.<|im_end|>\n"
156
- f"<|im_start|>user\nContext:\n{context}\n\nQuestion:\nSelect the most appropriate option:\n\nOptions:\n{opts_str}<|im_end|>\n"
157
- "<|im_start|>assistant\nDecision:"
158
  )
159
 
160
- # 3. Predict in 31 ms forward pass
161
- inputs = tokenizer(prompt, return_tensors="pt").to(device)
162
- with torch.no_grad():
163
- transformer = getattr(backbone, "model", backbone)
164
- out = transformer(inputs["input_ids"], attention_mask=inputs["attention_mask"])
165
- logits = head(out.last_hidden_state[:, -1, :], num_choices=torch.tensor([len(choices)], device=device))
166
- probs = F.softmax(logits[0, :len(choices)], dim=-1).cpu().tolist()
167
-
168
- for choice, prob in zip(choices, probs):
169
- print(f"{choice}: {prob * 100:.2f}%")
170
  ```
171
 
172
  ---
 
92
 
93
  ---
94
 
95
+ ## 🚀 Quickstart: Super Friendly 3-Line Decision
96
 
 
 
 
 
 
 
97
  ```python
98
+ from qjev import QJev
99
+
100
+ # 1. Load in 1 line:
101
+ model = QJev.from_pretrained("devankit7873/QJev-1.5B")
102
+
103
+ # 2. Decide in 31 ms!
104
+ result = model.decide(
105
+ context="Production database primary replica CPU spiked to 100% and connection pool is exhausted.",
106
+ choices=[
107
+ "Trigger immediate automated failover to standby replica",
108
+ "Restart the primary database daemon immediately",
109
+ "Double connection pool limits without scaling compute",
110
+ "Silence alerts and monitor for next 15 minutes"
111
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
  )
113
 
114
+ print(f"👉 Recommended: {result['best_choice']} ({result['confidence']}%)")
115
+ for choice, prob in result['probabilities'].items():
116
+ print(f" [{prob:>5.2f}%] {choice}")
 
 
 
 
 
 
 
117
  ```
118
 
119
  ---