Instructions to use btbtyler09/shrew-2b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use btbtyler09/shrew-2b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="btbtyler09/shrew-2b")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("btbtyler09/shrew-2b", device_map="auto") - PEFT
How to use btbtyler09/shrew-2b with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use btbtyler09/shrew-2b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "btbtyler09/shrew-2b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/shrew-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/btbtyler09/shrew-2b
- SGLang
How to use btbtyler09/shrew-2b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "btbtyler09/shrew-2b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/shrew-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "btbtyler09/shrew-2b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "btbtyler09/shrew-2b", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use btbtyler09/shrew-2b with Docker Model Runner:
docker model run hf.co/btbtyler09/shrew-2b
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -13,21 +13,34 @@ tags:
|
|
| 13 |
|
| 14 |
# Shrew LoRA Adapters
|
| 15 |
|
| 16 |
-
|
| 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 |
|
| 23 |
|---|---|---|---|
|
| 24 |
-
| `
|
| 25 |
-
| `
|
| 26 |
-
| `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
## Usage
|
| 29 |
|
| 30 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
```
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
```bash
|
| 45 |
-
llama-
|
| 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.
|
| 53 |
|
| 54 |
-
Apply the
|
| 55 |
|
| 56 |
```bash
|
| 57 |
python fix_lora_keys.py path/to/adapter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
```
|
| 59 |
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
|
| 62 |
Use Qwen 3.5 instruct-general parameters with `enable_thinking=False`:
|
| 63 |
|
| 64 |
-
|
| 65 |
-
-
|
| 66 |
-
|
|
|
|
|
|
|
| 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 |
|