barha commited on
Commit
1537da1
Β·
verified Β·
1 Parent(s): 5035d96

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +95 -2
README.md CHANGED
@@ -23,13 +23,106 @@ GGUF conversion of [ibm-granite/granite-switch-4.1-3b-preview](https://huggingfa
23
  |---|---|
24
  | `granite-switch-4.1-3b-preview-bf16.gguf` | bf16 GGUF, includes base model weights and all 12 embedded LoRA adapters |
25
 
26
- ## Usage
27
 
28
  ```bash
29
  llama-cli -m granite-switch-4.1-3b-preview-bf16.gguf -p "Hello"
30
  ```
31
 
32
- Refer to the original repo for adapter activation via control tokens (RAG, guardian, requirement-check, etc.) and the [Granite Switch](https://github.com/generative-computing/granite-switch) project.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  ## License
35
 
 
23
  |---|---|
24
  | `granite-switch-4.1-3b-preview-bf16.gguf` | bf16 GGUF, includes base model weights and all 12 embedded LoRA adapters |
25
 
26
+ ## Basic usage
27
 
28
  ```bash
29
  llama-cli -m granite-switch-4.1-3b-preview-bf16.gguf -p "Hello"
30
  ```
31
 
32
+ With no control token, the model runs as the plain base chat model.
33
+
34
+ ## Adapter activation
35
+
36
+ Granite Switch embeds 12 adapters in one checkpoint. An in-graph router selects
37
+ which adapter is active by detecting a control token in the prompt. The selection
38
+ is **per request (one adapter per generation)** β€” the control token routes the whole
39
+ sequence to a single adapter slot, then is substituted out before embedding so it
40
+ does not corrupt the text.
41
+
42
+ To activate an adapter you place its control token in the prompt at the position
43
+ the model was trained for. Placement differs by adapter type:
44
+
45
+ - **LoRA adapters** β€” the token goes at the very start, replacing the leading
46
+ `<|start_of_role|>`. Adapters: `citations`, `hallucination_detection`,
47
+ `context-attribution`.
48
+ - **aLoRA adapters** β€” the token is spliced right before the final
49
+ `assistant<|end_of_role|>` generation prompt (replacing its `<|start_of_role|>`).
50
+ Adapters: `query_rewrite`, `query_clarification`, `answerability`,
51
+ `factuality-detection`, `policy-guardrails`, `factuality-correction`,
52
+ `guardian-core`, `uncertainty`, `requirement-check`.
53
+
54
+ | Adapter | Type | Control token | Output |
55
+ |---|---|---|---|
56
+ | citations | lora | `<\|citations\|>` | citation spans |
57
+ | hallucination_detection | lora | `<\|hallucination_detection\|>` | `[{"r","f":faithful/partial/unfaithful/NA,"e"}]` |
58
+ | context-attribution | lora | `<\|context-attribution\|>` | attribution spans |
59
+ | query_rewrite | alora | `<\|query_rewrite\|>` | rewritten query |
60
+ | query_clarification | alora | `<\|query_clarification\|>` | clarification or `CLEAR` |
61
+ | answerability | alora | `<\|answerability\|>` | `answerable` / `unanswerable` |
62
+ | factuality-detection | alora | `<\|factuality-detection\|>` | `yes` / `no` |
63
+ | policy-guardrails | alora | `<\|policy-guardrails\|>` | `Yes` / `No` / `Ambiguous` |
64
+ | factuality-correction | alora | `<\|factuality-correction\|>` | corrected text |
65
+ | guardian-core | alora | `<\|guardian-core\|>` | `yes` / `no` (risk) |
66
+ | uncertainty | alora | `<\|uncertainty\|>` | `0`..`9` (certainty) |
67
+ | requirement-check | alora | `<\|requirement-check\|>` | `yes` / `no` |
68
+
69
+ ### Example: `hallucination_detection` (LoRA β€” token at start)
70
+
71
+ ```
72
+ <|hallucination_detection|>user<|end_of_role|>Tell me about the moon.<|end_of_text|>
73
+ <|start_of_role|>assistant<|end_of_role|>The moon is made of green cheese.<|end_of_text|>
74
+ <|start_of_role|>assistant<|end_of_role|>
75
+ ```
76
+ Produces the adapter's structured JSON, e.g.
77
+ `[{"r": 0, "f": "unfaithful", "e": "..."}]` instead of a chat reply.
78
+
79
+ ### Example: `answerability` (aLoRA β€” token before the assistant prompt)
80
+
81
+ ```
82
+ <|start_of_role|>system<|end_of_role|>You are a helpful assistant with access to the following documents...
83
+ <documents>
84
+ {"doc_id": "1", "text": "The square root of 4 is 2."}
85
+ </documents>
86
+ ...<|end_of_text|>
87
+ <|start_of_role|>user<|end_of_role|>What is the square root of 4?<|end_of_text|>
88
+ <|answerability|>assistant<|end_of_role|>
89
+ ```
90
+ Produces `answerable` (or `unanswerable` for a question the documents don't cover).
91
+
92
+ The exact formats above are what the model's own chat template renders. The
93
+ reliable way to build them is to render the template with `adapter_name` set β€”
94
+ `tokenizer.apply_chat_template(messages, documents=..., adapter_name="answerability",
95
+ add_generation_prompt=True, tokenize=False)` β€” rather than hand-constructing them.
96
+
97
+ ## Running the adapters with Ollama
98
+
99
+ Because adapter selection lives in the ggml graph and expects the control token
100
+ already present in the prompt, the cleanest path through Ollama is a **raw** request
101
+ where you supply the fully-rendered prompt yourself:
102
+
103
+ ```bash
104
+ ollama create granite-switch-4.1-3b-preview -f Modelfile # FROM the bf16 GGUF
105
+ ```
106
+
107
+ ```bash
108
+ curl http://localhost:11434/api/generate -d '{
109
+ "model": "granite-switch-4.1-3b-preview",
110
+ "raw": true,
111
+ "prompt": "<|start_of_role|>user<|end_of_role|><|hallucination_detection|>The moon is made of green cheese.<|end_of_text|>\n<|start_of_role|>assistant<|end_of_role|>",
112
+ "stream": false,
113
+ "options": {"temperature": 0}
114
+ }'
115
+ ```
116
+
117
+ `raw: true` bypasses Ollama's chat template so the control token reaches the model
118
+ verbatim. (The normal `/api/chat` path works too if you embed the token in the
119
+ message content, but it cannot reproduce the aLoRA boundary placement for you β€”
120
+ raw mode is the faithful option.)
121
+
122
+ A current Ollama build already includes granite-switch support, so **no patched
123
+ Ollama is required** β€” you can also drive the adapters with
124
+ [Mellea](https://mellea.ai/) against stock Ollama, letting Mellea render the
125
+ template and place the control tokens.
126
 
127
  ## License
128