btbtyler09 commited on
Commit
8f7f5c2
·
verified ·
1 Parent(s): 84c571e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +48 -19
README.md CHANGED
@@ -13,21 +13,34 @@ tags:
13
 
14
  # Shrew LoRA Adapters
15
 
16
- > **Work in progress** -- adapters are functional but under active development.
17
-
18
- LoRA adapters for [Qwen/Qwen3.5-2B](https://huggingface.co/Qwen/Qwen3.5-2B) fine-tuned for structured extraction as part of a production RAG application. These are the models that power [Shrew's](https://github.com/btbtyler09/shrew-server) structured extraction pipeline.
19
 
20
  ## Adapters
21
 
22
- | Adapter | Task | LoRA Rank | Status |
23
  |---|---|---|---|
24
- | `extract_metadata/` | Extract structured metadata (title, authors, dates, etc.) from document text | r32 / alpha 64 | Production |
25
- | `summarize_document/` | Generate document summaries | r32 / alpha 64 | Production |
26
- | `semantic_chunk/` | Split documents into semantically coherent sections | r128 / alpha 256 | Beta (50k subset, paused at 57%) |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
  ## Usage
29
 
30
- Load with PEFT on the base model:
31
 
32
  ```python
33
  from transformers import AutoModelForCausalLM, AutoTokenizer
@@ -35,35 +48,51 @@ from peft import PeftModel
35
 
36
  base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-2B")
37
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-2B")
 
38
 
39
- model = PeftModel.from_pretrained(base, "./extract_metadata")
 
 
 
 
40
  ```
41
 
42
- GGUF versions can be used with llama.cpp as LoRA adapters:
 
 
 
 
43
 
44
  ```bash
45
- llama-cli -m Qwen3.5-2B.gguf --lora semantic_chunk.gguf -p "<prompt>"
46
  ```
47
 
48
- For the full pipeline integration, see [shrew-server](https://github.com/btbtyler09/shrew-server).
49
-
50
  ### vLLM
51
 
52
- vLLM loads Qwen3.5 as `Qwen3_5ForConditionalGeneration` (VLM class), which nests the language model under a `language_model.` prefix. These adapters are saved in standard PEFT format (trained with `AutoModelForCausalLM`), so the weight keys must be renamed before serving with vLLM's `--enable-lora`. Without this, vLLM silently zeros all LoRA weights with no error.
53
 
54
- Apply the fix with `fix_lora_keys.py` from the [shrew](https://github.com/btbtyler09/shrew) repo:
55
 
56
  ```bash
57
  python fix_lora_keys.py path/to/adapter
 
 
 
 
 
58
  ```
59
 
60
- ## Sampling Parameters
 
 
61
 
62
  Use Qwen 3.5 instruct-general parameters with `enable_thinking=False`:
63
 
64
- - temperature: 0.7
65
- - top_p: 0.8
66
- - top_k: 20
 
 
67
 
68
  ## License
69
 
 
13
 
14
  # Shrew LoRA Adapters
15
 
16
+ LoRA adapters for [Qwen/Qwen3.5-2B](https://huggingface.co/Qwen/Qwen3.5-2B) fine-tuned for structured extraction as part of a production RAG application. These power [Shrew's](https://github.com/btbtyler09/shrew-server) structured extraction pipeline.
 
 
17
 
18
  ## Adapters
19
 
20
+ | Adapter | Tasks | LoRA rank / alpha | Status |
21
  |---|---|---|---|
22
+ | **`doc_processing/`** | `extract_metadata`, `semantic_chunk`, `summarize_document` (3 tasks, single adapter) | r128 / α256 | **Recommended** unified, supersedes the 3 per-task adapters below |
23
+ | `extract_metadata/` | Extract structured metadata (title, authors, dates, document type) | r32 / α64 | Superseded by `doc_processing/` |
24
+ | `summarize_document/` | Generate document summaries | r32 / α64 | Superseded by `doc_processing/` |
25
+ | `semantic_chunk/` | Split documents into semantically coherent sections | r128 / α256 | Superseded by `doc_processing/` |
26
+
27
+ The unified `doc_processing/` adapter routes by **system prompt** — the prompt is just the task name (`extract_metadata`, `semantic_chunk`, or `summarize_document`). One adapter, three tasks.
28
+
29
+ ### `doc_processing/` metrics
30
+
31
+ | | |
32
+ |---|---|
33
+ | Base model | `Qwen/Qwen3.5-2B` |
34
+ | LoRA rank / alpha | 128 / 256 |
35
+ | Adapter size | ~256 MB (f16) |
36
+ | Training corpus | ~103k examples across 3 tasks |
37
+ | Epochs | 3 |
38
+ | Final eval loss | 0.7103 |
39
+ | Hardware | 4× AMD MI100 (gfx908), bf16, DeepSpeed ZeRO-2 |
40
 
41
  ## Usage
42
 
43
+ The unified `doc_processing/` adapter routes by system prompt. Same adapter, different task per call.
44
 
45
  ```python
46
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
48
 
49
  base = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3.5-2B")
50
  tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3.5-2B")
51
+ model = PeftModel.from_pretrained(base, "btbtyler09/shrew-2b", subfolder="doc_processing")
52
 
53
+ messages = [
54
+ {"role": "system", "content": "extract_metadata"}, # or "semantic_chunk", "summarize_document"
55
+ {"role": "user", "content": document_text},
56
+ ]
57
+ prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
58
  ```
59
 
60
+ `extract_metadata` and `semantic_chunk` produce JSON; `summarize_document` produces prose.
61
+
62
+ ### llama.cpp (GGUF)
63
+
64
+ GGUF versions can be used as LoRA adapters with `llama-cli` / `llama-server`:
65
 
66
  ```bash
67
+ llama-server -m Qwen3.5-2B.gguf --lora doc_processing.gguf
68
  ```
69
 
 
 
70
  ### vLLM
71
 
72
+ vLLM loads Qwen3.5 as `Qwen3_5ForConditionalGeneration` (a VLM class), which nests the language model under a `language_model.` prefix. The adapters here are saved in standard PEFT format (trained with `AutoModelForCausalLM`), so the weight keys must be renamed before serving with vLLM's `--enable-lora`. Without the rename, vLLM silently zeros all LoRA weights with no error.
73
 
74
+ Apply the rename with `fix_lora_keys.py` from the [shrew](https://github.com/btbtyler09/shrew) repo:
75
 
76
  ```bash
77
  python fix_lora_keys.py path/to/adapter
78
+ vllm serve Qwen/Qwen3.5-2B \
79
+ --enable-lora \
80
+ --lora-modules doc_processing=path/to/adapter \
81
+ --max-lora-rank 128 \
82
+ --max-loras 1
83
  ```
84
 
85
+ Note `--max-lora-rank 128` for the unified adapter (vLLM's default of 16 is too low).
86
+
87
+ ## Sampling parameters
88
 
89
  Use Qwen 3.5 instruct-general parameters with `enable_thinking=False`:
90
 
91
+ | param | value |
92
+ |---|---|
93
+ | temperature | 0.7 |
94
+ | top_p | 0.8 |
95
+ | top_k | 20 |
96
 
97
  ## License
98