File size: 3,844 Bytes
4351668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
---
license: apache-2.0
base_model: Qwen/Qwen3-1.7B
library_name: peft
pipeline_tag: text-generation
language:
- en
tags:
- lora
- peft
- qwen3
- log-analysis
- prompt-compression
- token-compression
---

# Log reader: Qwen3-1.7B LoRA for template-compressed logs

A LoRA adapter for [Qwen3-1.7B](https://huggingface.co/Qwen/Qwen3-1.7B) that answers questions about server logs stored in a compact template format, so the prompt uses about 25% fewer tokens. It is part of the [token-compression](https://github.com/Garnet-Owl/token-compression) project.

## Results

Test set: 150 new 30-line logs, with three kinds of question (look up a request, highest duration, count the ERROR lines).

| Model and log | Correct | Prompt tokens |
| --- | --- | --- |
| Base Qwen3-1.7B, original log | 33% | 1,459 |
| Base Qwen3-1.7B, compressed log with a short legend | 16% | 1,147 |
| This adapter, original log | 77% | 1,459 |
| This adapter, compressed log, no legend | **73%** | **1,090** |

With 150 questions, the 4-point gap between the last two rows is within noise. Counting is the weak spot: 31% on compressed logs, against 100% for lookups and 90% for highest duration.

## The compressed format

Each repeated line shape is written once as a template, and every line becomes a short row of values:

```
@1 2026-11-12 {} INFO request_id={} method={} path={} status={} duration_ms={}
---
1|10:22:09|16480894|GET|/api/v1/orders/299|200|845
```

The compressor is lossless and lives in the GitHub repo (`app/structured_compression/compressor.py`).

## Usage

```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer
from app.structured_compression.compressor import StructuredCompressor  # from the GitHub repo

base = "Qwen/Qwen3-1.7B"
tokenizer = AutoTokenizer.from_pretrained(base)
model = AutoModelForCausalLM.from_pretrained(base, dtype=torch.float16, device_map="auto")
model = PeftModel.from_pretrained(model, "Garnet-Owl/token-compression-log-reader").eval()

INSTRUCTION = (
    "Reply with only the answer. For a request_id question give the status code and duration_ms. "
    "For a count or a highest value give just the number."
)
packed = StructuredCompressor().compress(log_text)
question = "How many ERROR lines are in the log?"
prompt = f"Log:\n{packed}\n\nQuestion: {question}\n{INSTRUCTION}"

text = tokenizer.apply_chat_template(
    [{"role": "user", "content": prompt}], tokenize=False, add_generation_prompt=True, enable_thinking=False
)
inputs = tokenizer(text, return_tensors="pt", add_special_tokens=False).to(model.device)
output = model.generate(**inputs, max_new_tokens=10, do_sample=False)
print(tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
```

On a CPU, load in `torch.float32` and drop `device_map`. It works but is slow.

## Training

- Base model: Qwen3-1.7B, fp16, LoRA rank 32 and alpha 64 on all linear layers (about 35M trainable parameters).
- Data: 1,470 synthetic log questions, about 80% compressed logs without a legend and 20% original logs. Loss on answer tokens only.
- One pass, learning rate 2e-4 with a cosine schedule, batches packed by token budget, gradient checkpointing, on one 16 GB T4 GPU in about 44 minutes.
- The scripts are in [`experiments/log_reader/`](https://github.com/Garnet-Owl/token-compression/tree/master/experiments/log_reader).

## Limitations

- Trained and tested on generated logs in one format, from a single random seed. Real logs are messier.
- It is specific to this template format and these question types. Other formats need their own training.
- Counting questions are unreliable.
- This is a research adapter, not a production log-analysis tool.

## Author

James Wanjiku. [GitHub](https://github.com/Garnet-Owl) | [LinkedIn](https://www.linkedin.com/in/james-wanjiku/)