File size: 6,286 Bytes
0810902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# Troubleshooting

## The model outputs `!!!!!!!!!!` (or one repeated token)

**This is the most likely failure you will hit.** It is a placement problem, not a broken
checkpoint.

Piko-9b is a hybrid model: 24 of its 32 layers use gated linear attention with a causal
convolution and a recurrent state kept in `float32` (`mamba_ssm_dtype`). That state does not
survive being split across CPU and GPU. When `device_map="auto"` cannot fit the model in VRAM it
silently offloads layers to CPU, the recurrent state is corrupted, and every logit collapses to
the same token.

It fails **silently**`from_pretrained` succeeds, generation runs, and you get fluent-looking
garbage.

Observed on an RTX 5070 Ti (17.1 GB) with `device_map="auto"`, bfloat16:

```
prompt : "Write a Python function that reverses a string."
output : "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
```

Same weights, same machine, 4-bit and fully resident on the GPU:

```
output : "The capital of France is Paris."
```

**Fix — keep the whole model on one device:**

```python
model = AutoModelForMultimodalLM.from_pretrained(
    "Dexy2/Piko-9b",
    dtype=torch.bfloat16,
    device_map={"": 0},          # not "auto"
    quantization_config=BitsAndBytesConfig(
        load_in_4bit=True,
        bnb_4bit_quant_type="nf4",
        bnb_4bit_compute_dtype=torch.bfloat16,
        bnb_4bit_use_double_quant=True,
    ),
)
```

If you have ≥ 22 GB of VRAM you can drop the quantization config and keep `device_map={"": 0}`.

**How to detect it in your own code:**

```python
if len(set(response.replace(" ", ""))) < 5:
    raise RuntimeError("Degenerate output — model is probably split across devices")
```

## `ImportError: ... requires the Torchvision library`

`transformers` 5.x uses tensor-based fast image processors. Without `torchvision`,
`AutoProcessor.from_pretrained` raises before the model is even touched — so this hits you even
if you only want text.

```bash
pip install torchvision
```

Match the build to your torch install. If no wheel exists for your Python version (this happens
on pre-release Pythons such as 3.15), use Python 3.10–3.12.

## `AttributeError: module 'transformers' has no attribute 'AutoModelForMultimodalLM'`

Your `transformers` is too old. Piko-9b needs **≥ 5.5**, not the `>= 4.57` quoted in some earlier
documentation.

```bash
pip install -U "transformers>=5.5"
```

The `"transformers_version": "4.57.0.dev0"` recorded inside `config.json` is stale build metadata
and should not be used to pick a version.

## `TypeError: embedding(): argument 'indices' must be Tensor, not BatchEncoding`

In `transformers` 5.x, `apply_chat_template(..., return_tensors="pt")` returns a `BatchEncoding`,
not a bare tensor. Either index it, or ask for a dict:

```python
inputs = processor.apply_chat_template(
    messages, add_generation_prompt=True, tokenize=True,
    return_dict=True, return_tensors="pt",
).to(model.device)
model.generate(**inputs, max_new_tokens=256)
```

## `The fast path is not available ... install flash-linear-attention / causal-conv1d`

A warning, not an error. The linear-attention layers fall back to a pure-PyTorch implementation
and everything still works, just more slowly.

```bash
pip install flash-linear-attention causal-conv1d
```

These require a recent torch; if the log says *"Skipping import of cpp extensions due to
incompatible torch version"*, the kernels are installed but unused, which is harmless.

This is **not** FlashAttention-2. Only 8 of the 32 layers use softmax attention at all, so
FlashAttention-2 has far less effect here than on a conventional transformer.

## CUDA out of memory

| Symptom | Action |
|---|---|
| OOM while loading | Use `--quantization 4bit`. Do **not** switch to `device_map="auto"` |
| OOM during generation on long prompts | KV cache for the 8 full-attention layers grows with length; shorten the prompt or lower `max_new_tokens` |
| OOM only when batching | Lower `--batch-size`; padding makes every sequence as long as the longest |

Do not set `max_memory` to force a CPU spill. That reintroduces the offload bug above.

## The model prints its reasoning

Piko-9b emits a `<think> … </think>` span before its answer. Strip it:

```python
answer = text.rsplit("</think>", 1)[-1].strip() if "</think>" in text else text.strip()
```

The examples in `examples/` do this by default; pass `--show-reasoning` to keep it.

## Output is identical every time / ignores `temperature`

`generation_config.json` sets no sampling parameters, so the shipped default is **greedy**.
Passing `temperature` alone does nothing — you must also pass `do_sample=True`:

```python
model.generate(**inputs, do_sample=True, temperature=0.7, top_p=0.95, max_new_tokens=512)
```

## `trust_remote_code=True` prompts or warnings

Not needed. This repository contains no `.py` files and no `auto_map`; the architecture is
native to `transformers`. Remove the flag.

## Batched outputs are wrong for short prompts

Check that padding stays on the left (`tokenizer_config.json` sets `padding_side: "left"`). Right
padding puts pad tokens between the prompt and the first generated token and corrupts
decoder-only generation.

## Image questions get vague or wrong answers

This is expected behaviour for this checkpoint, not a configuration error. The vision tower was
copied unchanged from `Qwen/Qwen3.5-9B` and was never trained or re-aligned against Piko's
fine-tuned language backbone. See [`reports/lineage_analysis.md`](../reports/lineage_analysis.md)
§4 and the measured results in the model card. If you need reliable document reading, use
`Qwen/Qwen3.5-9B` itself, where the tower and the backbone match.

## Windows notes

* Native Windows works, but `bitsandbytes` support is version-sensitive; if 4-bit fails to load,
  WSL2 with Ubuntu is the smoother path.
* Loading 21 GB from an external USB drive is I/O bound and can take 10–20 minutes. Copy the
  checkpoint to internal NVMe first — subsequent loads take seconds.
* Long paths: enable `LongPathsEnabled` or keep the checkout near the drive root.

## Linux notes

* Set `PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True` to reduce fragmentation on long runs.
* `TOKENIZERS_PARALLELISM=false` silences fork warnings during evaluation.