armaniii commited on
Commit
51a7711
Β·
verified Β·
1 Parent(s): 9a59442

Model card v3: step-by-step gated-access walkthrough, separate GPU/CPU quickstarts with hardware requirements, batch processing with tqdm progress bar

Browse files
Files changed (1) hide show
  1. README.md +70 -16
README.md CHANGED
@@ -47,11 +47,39 @@ Because the trained `score` head ships inside the adapter file, loading this ada
47
 
48
  > **Checkpoint format note:** the adapter was originally trained and saved with PEFT 0.7.1, whose `score`-head layout cannot be loaded by modern PEFT (β‰₯0.10 raises `KeyError: 'base_model.model.score.weight'`). The files on `main` were converted to the modern format (trained head merged as `base_layer + (alpha/r)Β·BΒ·A`) and verified **logit-equivalent to the original, on both the modern stack (peft 0.19.1) and the original stack (peft 0.7.1)** β€” `main` works everywhere. The original-format files are preserved at `revision="937b9babeb146587b5a9463b239ae4ca6ad26e18"`.
49
 
50
- ## Quickstart
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  ```bash
53
  pip install torch transformers peft accelerate sentencepiece
54
- huggingface-cli login # base model is gated
55
  ```
56
 
57
  ```python
@@ -71,6 +99,34 @@ model = PeftModel.from_pretrained(base, ADAPTER)
71
  model.eval()
72
  ```
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  ### Prompt format (must match training)
75
 
76
  The model uses the Llama-2 instruction wrapper with the WIBA argument-definition system prompt (the same system prompt as the detect stage), and takes **both the target topic and the text**:
@@ -127,25 +183,23 @@ print(classify_stance("climate change", "The weather is nice today."))
127
 
128
  The repo tokenizer's `<unk>` pad token (id 0) is in-vocabulary, so batched inference with `padding=True` works as-is.
129
 
130
- ## Memory-efficient loading (production configuration)
131
 
132
- The WIBA platform serves the 7B base 4-bit quantized (~4–5 GB VRAM instead of ~14 GB fp16). Requires a CUDA GPU and `pip install bitsandbytes`:
133
 
134
  ```python
135
- from transformers import BitsAndBytesConfig
 
136
 
137
- bnb_config = BitsAndBytesConfig(
138
- load_in_4bit=True,
139
- bnb_4bit_quant_type="nf4",
140
- bnb_4bit_use_double_quant=False,
141
- bnb_4bit_compute_dtype=torch.float16,
142
- )
143
- base = AutoModelForSequenceClassification.from_pretrained(
144
- BASE, num_labels=3, device_map="auto", quantization_config=bnb_config
145
- )
146
- ```
147
 
148
- For batched inference, use a `text-classification` pipeline exactly as the original implementation does: `pipeline(task="text-classification", model=model, tokenizer=tokenizer, padding=True, truncation=True, max_length=2048)`.
 
 
 
 
 
149
 
150
  ## Tested configurations
151
 
 
47
 
48
  > **Checkpoint format note:** the adapter was originally trained and saved with PEFT 0.7.1, whose `score`-head layout cannot be loaded by modern PEFT (β‰₯0.10 raises `KeyError: 'base_model.model.score.weight'`). The files on `main` were converted to the modern format (trained head merged as `base_layer + (alpha/r)Β·BΒ·A`) and verified **logit-equivalent to the original, on both the modern stack (peft 0.19.1) and the original stack (peft 0.7.1)** β€” `main` works everywhere. The original-format files are preserved at `revision="937b9babeb146587b5a9463b239ae4ca6ad26e18"`.
49
 
50
+ ## Before you start: get access to the gated Meta base model (one-time, ~10 minutes)
51
+
52
+ This adapter repo is freely downloadable, but the Meta base model it sits on is **gated** β€” Meta requires you to accept their license before you can download it. Step by step:
53
+
54
+ 1. **Create a Hugging Face account** (free): go to [huggingface.co/join](https://huggingface.co/join), sign up, and verify your email.
55
+ 2. **Request access to the base model**: while logged in, open [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf). At the top of the page is a box saying you need to share your contact information to access the model. Fill in the short form, accept the license, and submit.
56
+ 3. **Wait for the approval email** β€” usually minutes to a few hours. When the box on the model page changes to "You have been granted access", you're in.
57
+ 4. **Create an access token**: click your avatar (top right) β†’ **Settings** β†’ **Access Tokens** β†’ **Create new token** β†’ type **Read** β†’ create, and **copy the token** (it looks like `hf_...`). Treat it like a password.
58
+ 5. **Log in on your computer**: in a terminal run
59
+
60
+ ```bash
61
+ pip install -U "huggingface_hub[cli]"
62
+ huggingface-cli login
63
+ ```
64
+
65
+ and paste the token when prompted (nothing is shown as you paste β€” that's normal). Verify with `huggingface-cli whoami`, which should print your username.
66
+
67
+ This is once per computer. From then on, the code below downloads everything it needs automatically β€” you'll see progress bars for each file on the first run (~13.6 GB total), after which everything is cached in `~/.cache/huggingface` and loads from disk.
68
+
69
+ ## Hardware requirements β€” pick your setup
70
+
71
+ | Setup | What you need | Speed |
72
+ |---|---|---|
73
+ | **GPU, fp16** | NVIDIA GPU with β‰₯15 GB free VRAM (e.g. RTX 4090, A100; 16 GB cards work) | sub-second per text |
74
+ | **GPU, 4-bit** | NVIDIA GPU with β‰₯6 GB free VRAM, plus `pip install bitsandbytes` | fast β€” this is the wiba.dev production configuration |
75
+ | **CPU only** | ~30 GB free RAM, no GPU | ~15–25 s per text on 16 cores β€” fine for trying it out, slow for bulk work |
76
+
77
+ One-time download for any setup: ~13.6 GB (base model + adapter).
78
+
79
+ ## Quickstart β€” GPU
80
 
81
  ```bash
82
  pip install torch transformers peft accelerate sentencepiece
 
83
  ```
84
 
85
  ```python
 
99
  model.eval()
100
  ```
101
 
102
+ **Low VRAM? Load the base 4-bit instead** (β‰ˆ5 GB VRAM, the production setting β€” needs `pip install bitsandbytes`):
103
+
104
+ ```python
105
+ from transformers import BitsAndBytesConfig
106
+
107
+ bnb_config = BitsAndBytesConfig(
108
+ load_in_4bit=True,
109
+ bnb_4bit_quant_type="nf4",
110
+ bnb_4bit_use_double_quant=False,
111
+ bnb_4bit_compute_dtype=torch.float16,
112
+ )
113
+ base = AutoModelForSequenceClassification.from_pretrained(
114
+ BASE, num_labels=3, device_map="auto", quantization_config=bnb_config
115
+ )
116
+ ```
117
+
118
+ ## Quickstart β€” CPU (no GPU)
119
+
120
+ Identical to the GPU code, except load the base in float32 on the CPU:
121
+
122
+ ```python
123
+ base = AutoModelForSequenceClassification.from_pretrained(
124
+ BASE, num_labels=3, dtype=torch.float32, device_map="cpu"
125
+ )
126
+ ```
127
+
128
+ Expect ~15–25 s per prediction on a 16-core machine (verified). Make sure you have ~30 GB of free RAM before starting β€” on machines without swap, overshooting RAM can freeze the system.
129
+
130
  ### Prompt format (must match training)
131
 
132
  The model uses the Llama-2 instruction wrapper with the WIBA argument-definition system prompt (the same system prompt as the detect stage), and takes **both the target topic and the text**:
 
183
 
184
  The repo tokenizer's `<unk>` pad token (id 0) is in-vocabulary, so batched inference with `padding=True` works as-is.
185
 
186
+ ## Batch processing many texts (with a progress bar)
187
 
188
+ Model downloads show progress bars automatically; inference doesn't, so wrap batches in `tqdm` (installed with transformers) exactly as the original WIBA serving code does. The repo's `<unk>` pad token works for batching as-is:
189
 
190
  ```python
191
+ from tqdm import tqdm
192
+ from transformers import pipeline
193
 
194
+ clf = pipeline("text-classification", model=model, tokenizer=tokenizer,
195
+ padding=True, truncation=True, max_length=2048)
 
 
 
 
 
 
 
 
196
 
197
+ pairs = [("climate change", "..."), ("gun control", "...")] # (topic, text) pairs
198
+ prompts = [f"[INST] <<SYS>>\n{SYSTEM_PROMPT}\n<</SYS>>\n\nTarget: '{topic}' Text: '{text}' [/INST] "
199
+ for topic, text in pairs]
200
+ idx = {"LABEL_0": "No Argument", "LABEL_1": "Argument in Favor", "LABEL_2": "Argument Against"}
201
+ labels = [idx[out["label"]] for out in tqdm(clf(prompts, batch_size=4), total=len(prompts))]
202
+ ```
203
 
204
  ## Tested configurations
205