Repository: ollama
Issue: Crashing or gibberish output on 3x Radeon GPUs
Labels: bug,amd

### What is the issue?

While running mixtral:8x7b-instruct-v0.1-q4_K_M on my physical machine with x3 7900 XTX I got this error: 

```
[root@5dc6ecf27031 /]# ollama run mixtral:8x7b-instruct-v0.1-q4_K_M
Error: llama runner process has terminated: signal: segmentation fault (core dumped) 
[root@5dc6ecf27031 /]# 
```

Logs:

```
[GIN] 2024/07/11 - 13:22:44 | 200 |       16.23µs |       127.0.0.1 | HEAD     "/"
[GIN] 2024/07/11 - 13:22:44 | 200 |    7.724554ms |       127.0.0.1 | POST     "/api/show"
time=2024-07-11T13:22:44.297Z level=INFO source=sched.go:754 msg="new model will fit in available VRAM, loading" model=/root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8 library=rocm parallel=4 required="33.2 GiB"
time=2024-07-11T13:22:44.298Z level=INFO source=memory.go:309 msg="offload to rocm" layers.requested=-1 layers.model=33 layers.offload=33 layers.split=11,11,11 memory.available="[24.0 GiB 24.0 GiB 24.0 GiB]" memory.required.full="33.2 GiB" memory.required.partial="33.2 GiB" memory.required.kv="1.0 GiB" memory.required.allocations="[11.3 GiB 11.3 GiB 10.6 GiB]" memory.weights.total="25.5 GiB" memory.weights.repeating="25.4 GiB" memory.weights.nonrepeating="102.6 MiB" memory.graph.full="1.3 GiB" memory.graph.partial="1.3 GiB"
time=2024-07-11T13:22:44.299Z level=INFO source=server.go:375 msg="starting llama server" cmd="/tmp/ollama1419561683/runners/rocm_v60101/ollama_llama_server --model /root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8 --ctx-size 8192 --batch-size 512 --embedding --log-disable --n-gpu-layers 33 --parallel 4 --tensor-split 11,11,11 --tensor-split 11,11,11 --port 41695"
time=2024-07-11T13:22:44.299Z level=INFO source=sched.go:474 msg="loaded runners" count=1
time=2024-07-11T13:22:44.299Z level=INFO source=server.go:563 msg="waiting for llama runner to start responding"
time=2024-07-11T13:22:44.299Z level=INFO source=server.go:604 msg="waiting for server to become available" status="llm server error"
INFO [main] build info | build=1 commit="a8db2a9" tid="140134008951616" timestamp=1720704164
INFO [main] system info | n_threads=16 n_threads_batch=-1 system_info="AVX = 1 | AVX_VNNI = 0 | AVX2 = 0 | AVX512 = 0 | AVX512_VBMI = 0 | AVX512_VNNI = 0 | AVX512_BF16 = 0 | FMA = 0 | NEON = 0 | SVE = 0 | ARM_FMA = 0 | F16C = 0 | FP16_VA = 0 | WASM_SIMD = 0 | BLAS = 1 | SSE3 = 1 | SSSE3 = 1 | VSX = 0 | MATMUL_INT8 = 0 | LLAMAFILE = 0 | " tid="140134008951616" timestamp=1720704164 total_threads=32
INFO [main] HTTP server listening | hostname="127.0.0.1" n_threads_http="31" port="41695" tid="140134008951616" timestamp=1720704164
llama_model_loader: loaded meta data with 26 key-value pairs and 995 tensors from /root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8 (version GGUF V3 (latest))
llama_model_loader: Dumping metadata keys/values. Note: KV overrides do not apply in this output.
llama_model_loader: - kv   0:                       general.architecture str              = llama
llama_model_loader: - kv   1:                               general.name str              = mistralai
llama_model_loader: - kv   2:                       llama.context_length u32              = 32768
llama_model_loader: - kv   3:                     llama.embedding_length u32              = 4096
llama_model_loader: - kv   4:                          llama.block_count u32              = 32
llama_model_loader: - kv   5:                  llama.feed_forward_length u32              = 14336
llama_model_loader: - kv   6:                 llama.rope.dimension_count u32              = 128
llama_model_loader: - kv   7:                 llama.attention.head_count u32              = 32
llama_model_loader: - kv   8:              llama.attention.head_count_kv u32              = 8
llama_model_loader: - kv   9:                         llama.expert_count u32              = 8
llama_model_loader: - kv  10:                    llama.expert_used_count u32              = 2
llama_model_loader: - kv  11:     llama.attention.layer_norm_rms_epsilon f32              = 0.000010
llama_model_loader: - kv  12:                       llama.rope.freq_base f32              = 1000000.000000
llama_model_loader: - kv  13:                          general.file_type u32              = 15
llama_model_loader: - kv  14:                       tokenizer.ggml.model str              = llama
llama_model_loader: - kv  15:                      tokenizer.ggml.tokens arr[str,32000]   = ["<unk>", "
", "
", "<0x00>", "<...
llama_model_loader: - kv  16:                      tokenizer.ggml.scores arr[f32,32000]   = [0.000000, 0.000000, 0.000000, 0.0000...
llama_model_loader: - kv  17:                  tokenizer.ggml.token_type arr[i32,32000]   = [2, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, ...
llama_model_loader: - kv  18:                      tokenizer.ggml.merges arr[str,58980]   = ["▁ t", "i n", "e r", "▁ a", "h e...
llama_model_loader: - kv  19:                tokenizer.ggml.bos_token_id u32              = 1
llama_model_loader: - kv  20:                tokenizer.ggml.eos_token_id u32              = 2
llama_model_loader: - kv  21:            tokenizer.ggml.unknown_token_id u32              = 0
llama_model_loader: - kv  22:               tokenizer.ggml.add_bos_token bool             = true
llama_model_loader: - kv  23:               tokenizer.ggml.add_eos_token bool             = false
llama_model_loader: - kv  24:                    tokenizer.chat_template str              = {{ bos_token }}{% for message in mess...
llama_model_loader: - kv  25:               general.quantization_version u32              = 2
llama_model_loader: - type  f32:   65 tensors
llama_model_loader: - type  f16:   32 tensors
llama_model_loader: - type q8_0:   64 tensors
llama_model_loader: - type q4_K:  833 tensors
llama_model_loader: - type q6_K:    1 tensors
llm_load_vocab: special tokens cache size = 259
llm_load_vocab: token to piece cache size = 0.1637 MB
llm_load_print_meta: format           = GGUF V3 (latest)
llm_load_print_meta: arch             = llama
llm_load_print_meta: vocab type       = SPM
llm_load_print_meta: n_vocab          = 32000
llm_load_print_meta: n_merges         = 0
llm_load_print_meta: vocab_only       = 0
llm_load_print_meta: n_ctx_train      = 32768
llm_load_print_meta: n_embd           = 4096
llm_load_print_meta: n_layer          = 32
llm_load_print_meta: n_head           = 32
llm_load_print_meta: n_head_kv        = 8
llm_load_print_meta: n_rot            = 128
llm_load_print_meta: n_swa            = 0
llm_load_print_meta: n_embd_head_k    = 128
llm_load_print_meta: n_embd_head_v    = 128
llm_load_print_meta: n_gqa            = 4
llm_load_print_meta: n_embd_k_gqa     = 1024
llm_load_print_meta: n_embd_v_gqa     = 1024
llm_load_print_meta: f_norm_eps       = 0.0e+00
llm_load_print_meta: f_norm_rms_eps   = 1.0e-05
llm_load_print_meta: f_clamp_kqv      = 0.0e+00
llm_load_print_meta: f_max_alibi_bias = 0.0e+00
llm_load_print_meta: f_logit_scale    = 0.0e+00
llm_load_print_meta: n_ff             = 14336
llm_load_print_meta: n_expert         = 8
llm_load_print_meta: n_expert_used    = 2
llm_load_print_meta: causal attn      = 1
llm_load_print_meta: pooling type     = 0
llm_load_print_meta: rope type        = 0
llm_load_print_meta: rope scaling     = linear
llm_load_print_meta: freq_base_train  = 1000000.0
llm_load_print_meta: freq_scale_train = 1
llm_load_print_meta: n_ctx_orig_yarn  = 32768
llm_load_print_meta: rope_finetuned   = unknown
llm_load_print_meta: ssm_d_conv       = 0
llm_load_print_meta: ssm_d_inner      = 0
llm_load_print_meta: ssm_d_state      = 0
llm_load_print_meta: ssm_dt_rank      = 0
llm_load_print_meta: model type       = 8x7B
llm_load_print_meta: model ftype      = Q4_K - Medium
llm_load_print_meta: model params     = 46.70 B
llm_load_print_meta: model size       = 24.62 GiB (4.53 BPW) 
llm_load_print_meta: general.name     = mistralai
llm_load_print_meta: BOS token        = 1 '
'
llm_load_print_meta: EOS token        = 2 '
'
llm_load_print_meta: UNK token        = 0 '<unk>'
llm_load_print_meta: LF token         = 13 '<0x0A>'
llm_load_print_meta: max token length = 48
time=2024-07-11T13:22:44.549Z level=INFO source=server.go:604 msg="waiting for server to become available" status="llm server loading model"
ggml_cuda_init: GGML_CUDA_FORCE_MMQ:    no
ggml_cuda_init: GGML_CUDA_FORCE_CUBLAS: no
ggml_cuda_init: found 3 ROCm devices:
  Device 0: Radeon RX 7900 XTX, compute capability 11.0, VMM: no
  Device 1: Radeon RX 7900 XTX, compute capability 11.0, VMM: no
  Device 2: Radeon RX 7900 XTX, compute capability 11.0, VMM: no
llm_load_tensors: ggml ctx size =    1.53 MiB
llm_load_tensors: offloading 32 repeating layers to GPU
llm_load_tensors: offloading non-repeating layers to GPU
llm_load_tensors: offloaded 33/33 layers to GPU
llm_load_tensors:      ROCm0 buffer size =  8608.53 MiB
llm_load_tensors:      ROCm1 buffer size =  8608.53 MiB
llm_load_tensors:      ROCm2 buffer size =  7928.49 MiB
llm_load_tensors:  ROCm_Host buffer size =    70.31 MiB
time=2024-07-11T13:23:03.566Z level=INFO source=server.go:604 msg="waiting for server to become available" status="llm server not responding"
llama_new_context_with_model: n_ctx      = 8192
llama_new_context_with_model: n_batch    = 512
llama_new_context_with_model: n_ubatch   = 512
llama_new_context_with_model: flash_attn = 0
llama_new_context_with_model: freq_base  = 1000000.0
llama_new_context_with_model: freq_scale = 1
time=2024-07-11T13:23:04.460Z level=INFO source=server.go:604 msg="waiting for server to become available" status="llm server loading model"
llama_kv_cache_init:      ROCm0 KV buffer size =   352.00 MiB
llama_kv_cache_init:      ROCm1 KV buffer size =   352.00 MiB
llama_kv_cache_init:      ROCm2 KV buffer size =   320.00 MiB
llama_new_context_with_model: KV self size  = 1024.00 MiB, K (f16):  512.00 MiB, V (f16):  512.00 MiB
llama_new_context_with_model:  ROCm_Host  output buffer size =     0.55 MiB
llama_new_context_with_model: pipeline parallelism enabled (n_copies=4)
llama_new_context_with_model:      ROCm0 compute buffer size =   640.01 MiB
llama_new_context_with_model:      ROCm1 compute buffer size =   640.01 MiB
llama_new_context_with_model:      ROCm2 compute buffer size =   640.02 MiB
llama_new_context_with_model:  ROCm_Host compute buffer size =    72.02 MiB
llama_new_context_with_model: graph nodes  = 1510
llama_new_context_with_model: graph splits = 4
time=2024-07-11T13:23:06.864Z level=INFO source=server.go:604 msg="waiting for server to become available" status="llm server error"
[GIN] 2024/07/11 - 13:23:07 | 500 | 22.834580361s |       127.0.0.1 | POST     "/api/chat"
time=2024-07-11T13:23:07.115Z level=ERROR source=sched.go:480 msg="error loading llama server" error="llama runner process has terminated: signal: segmentation fault (core dumped) "
time=2024-07-11T13:23:12.116Z level=WARN source=sched.go:671 msg="gpu VRAM usage didn't recover within timeout" seconds=5.001085328 model=/root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8
time=2024-07-11T13:23:12.366Z level=WARN source=sched.go:671 msg="gpu VRAM usage didn't recover within timeout" seconds=5.251122065 model=/root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8
time=2024-07-11T13:23:12.616Z level=WARN source=sched.go:671 msg="gpu VRAM usage didn't recover within timeout" seconds=5.500799906 model=/root/.ollama/models/blobs/sha256-3a17f7cde150070bbc815645693fb93c311cc42e7deaf198364acadcf08458f8

```

I am running this docker version

docker run -d --restart unless-stopped --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama  -p 11442:11434 --name dvz3 ollama/ollama:0.2.1-rocm



### OS

Linux

### GPU

AMD

### CPU

AMD

### Ollama version

0.2.1-rocm