Local neural net inference

I want to experiment with neural network inference on my local laptop with GPU 8GB. So I have Archlinux qemu virtual machine with RTX5070 8G pass troughn in.

llm usage on my own laptop vllm with inteligencia artificial and Development|lower


LOCAL INFERENCE

Download model from Huggingface

1. How to download model with curl:

HF_TOKEN="hf_your_token_here"

MODEL_URL="https://huggingface.co/Qwen/Qwen2.5-7B-Instruct-AWQ/resolve/main/model.safetensors?download=true"

curl -H "Authorization: Bearer $HF_TOKEN" -o model.safetensors $MODEL_URL

unzip model.safetensors -d ./data/vllm-models/Qwen2.5-7B-Instruct-AWQ

 

2. Most convenient way to install.

$ pip install huggingface_hub

$ hf auth login --token $HF_TOK

$ hf download Qwen/Qwen2.5-7B-Instruct-AWQ \

  --local-dir ./data/vllm-models/Qwen2.5-7B-Instruct-AWQ \

  --token $HF_TOK

 

INFERENCE

0. To get multitab functionality on Linux sh CLI $ pacman -S tmux

1. Install vLLM (GPU-optimized) $ pip install vllm

2. Start the API server

vllm serve \

  ./data/vllm-models/Qwen2.5-7B-Instruct-AWQ \ # use full path or huggingface name like Qwen/Qwen2.5 the model will be auto downloaded.

  --port 8000 \

  --dtype auto \

  --quantization awq \

  &>/dev/null &  # Silences output & runs in background

2.1. $ vllm serve produces error OSError Repo id must be in the form repo_name or namespace/repo_name /model/Qwen1.5-1.8B Use repo type argument if needed // Use HF format Qwen/Qwen3 it will be downloaded automatically.

2.2. Models downloaded to ~/.cache/huggingface/hub

3. To test $ curl -X POST http://localhost:8000/v1/completions \

  -H "Content-Type: application/json" \

  -d '{"prompt": "Explain quantum computing in simple terms", "max_tokens": 100}'

 

PYTHON

1. Code:

from vllm import LLM, SamplingParams

prompts = ["The capital of France is", "The future of AI is",]

sampling_params = SamplingParams(temperature=0.8, top_p=0.95, max_token=100)

llm = LLM(model="/your/local/path/to/model/")

outputs = llm.generate(prompts, sampling_params)

for output in outputs:

    prompt = output.prompt

    generated_text = output.outputs[0].text

    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

1.1. Shows error on llm = LLM(...  Value error: to serve at least one request with the models max seq len (32768), 6.0 GiB KV cache is needed which is larger than the available KV cache mamory (2.59 GiB). Based on the available memory, the estimated maximum model lenght is 14160. Try increasing 'gpu_memory_utilization' or decreasing 'max_model_len' when initializing the engine. 

Try to decrease KV cache:

llm = LLM(

    model="/home/user/Qwen1.5-1.8B/",

    max_model_len=8192,                     # or 14160 (estimated safe max)

    gpu_memory_utilization=0.95,            # increase from default 0.9

    trust_remote_code=True                  # optional, but safe for Qwen

)

1.2. I am trying to use model Qwen3-4B-Instruct-2507-FP8. While initializing LLM() Get an error: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 76.00 MiB. GPU 0 has a total capacity of 7.53GiB of which 27.31MiB is free. Including non-Python memory, this process has 7.48 GiB memory in use. Of the allocated memory 7.21 GiB is allocated by Pytorch, and 35.08 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.

Try gpu_memory_utilization=0.70 and kv_cache_dtype="auto"

 

LOCAL VLLM INTEGRATION TO VSCODE

0. To monitor GPU VRAM usage online $ watch -n 1 'nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader'

1. I will use Qwen2.5-Coder-7B-Instruct-GPTQ-Int4 on my 8 VRAM.

2. Start server:

$ vllm serve /path/to/Qwen2.5-Coder-7B-Instruct-GPTQ-Int4 \

  --quantization gptq \ # Compress weight 4 times

  --dtype auto \

  --max-model-len 25000 \

  --gpu-memory-utilization 0.87 \

  --kv_cache_dtype fp8 \  # Allows to compress KV cache and reduce VRAM usage but it significantly decrease answers quality the model becomes noticible stupid

  --enforce-eager \

  --trust-remote-code \

  --host 0.0.0.0 \

  --port 8000 \

  --enable-auto-tool-choice \

  --tool-call-parser hermes

3. Open VS Code → Extensions → Search Continue → Install (Continue.continue) // docs.continue.dev

4. Edit /home/user/./continue/config.yaml

models:

  - name: Qwen2.5-Coder-7B

    provider: openai

    model: Qwen2.5-Coder-7B-Instruct-GPTQ-Int4

    apiBase: http://127.0.0.1:8000/v1

    apiKey: sk-dummy-local

    defaultCompletionOptions:

      temperature: 0.2

      topP: 0.95

      maxTokens: 512

      contextLength: 2048

    capabilities:

    - tool_use      # Enable if your model supports function calling

    - image_input   # Enable for vision models

 

rules: You are an expert developer. Write clean, production-ready code with type hints. Prefer standard libraries. Be concise. Output only code when asked. You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside <think> </think> tags, and then provide your solution or response to the problem.

5. When I wanted to call some tools from continue agent I get an error 400 'auto' tool choice requires --enable-auto-tool-choice and --tool-call-parser to be set.

5.1. Restart vllm server with:

$ vllm serve /path/to/Qwen2.5-Coder-7B-Instruct-GPTQ-Int4 \

  --enable-auto-tool-choice \

  --tool-call-parser hermes

 

 

HOW TO CONNECT FIREWORKS LLM GATEWAY

1. Edit /home/user/./continue/config.yaml

models:

  - name: Fireworks Deepseek-V4-Pro

    provider: openai

    model: accounts/fireworks/models/deepseek-v4-pro 

    apiBase: https://api.fireworks.ai/inference/v1

    apiKey: your-key-here

 

Build custom Agent

1. vllm is running Qwen2.5-7B-Instruct-GPTQ-Int4 with --enable-auto-tool-choice --tool-call-parser qwen3_xml  But your request Calculate 15 * 27 and then add 100 produces empty tool_calls=[] in responce Instead it produces tool call in other way like message.content = '<tool_call> ... </tool_call>

1.1. In vllm derver set --tool-call-parser hermes

2. Build custom agent is much better then using some frameworks like Langchain. Because it actually easy especially with coding agents. You need just while cicle for ReAct. I have vibe coded pretty much good agent for one day.

 

How to increase context window.

0. On my 8GB GPU Qwen2.5-7B-Instruct-GPTQ-Int4 allows 21000 maximum, Qwen3-4B-AWQ allowed 29000 context window.

1. To increase set --kv_cache_dtype fp8 instead of auto. It allows on Qwen3-4B to increase context up to 40000 but it hitted models own limit not hardware one.

2. To surpass Qwen3 model limit use Yarn to use:  // It allows to increase --max-model-len to 50000

--hf-overrides '{

"rope_parameters": {

"rope_type": "yarn",
"factor": 2.0,
"original_max_position_embeddings": 32768,
"rope_theta": 1000000

}

}'

3. Qwen3-4B thinks too much spends tokens and impair tools usage actually. How to switch it off.

--default-chat-template-kwargs '{"enable_thinking": false}'

 

 

LLAMA.CPP

1. VLLM server developed for multiple users. It reserves a lot of KV cache VRAM. For my own usage best and more VRAM effective option is to use llama.cpp

2. $ git clone https://github.com/ggml-org/llama.cpp && cd llama.cpp

3. $ cmake -B build -DGGML_CUDA=ON -DGGML_CUDA_FA=ON // Configure the build with CUDA enabled and flash-attention enabled

4. Compile using all your CPU cores $ cmake --build build --config Release -j$(nproc)

5. For llama.cpp GGUF model needed.

6. If model has splited file like:

q4_0-00001-of-00002.gguf

q4_0-00002-of-00002.gguf

Use first file then 

./build/bin/llama-server \

    -m models/q4_0-00001-of-00002.gguf \

    -c 16384 \

    -ngl 99 \

    -ctk q8_0 \

    -ctv q8_0 \

    --flash-attn \

    --host 0.0.0.0 \

    --port 8080

 

$ ./llama-server -m ~/models/Qwen2.5-7B-Instruct-GGUF/qwen2.5-7b-instruct-q4_0-00001-of-00002.gguf -c 66384 -ngl 99 -ctk q8_0 -ctv q8_0 --flash-attn 'auto' --host 0.0.0.0 --port 8080  --temp 1.0 --top-k 40 --top-p 0.95 --min-p 0

 

USE RAM + GPU

1. With 8GB GPU the largest LLM is 7B. I could use is I want to use strongest maximum model. Maybe I could use my 30 GB RAM to sacrifice speed but get strongest model.

2. In llama.cpp you can explicitly define how many model layers will be loaded in GPU with -ngl option. Recent layers will be automatically loaded to RAM.

$ ./llama-server \

-m /home/user/model/qwen2.5-coder-14b-instruct-GGUF/qwen2.5-coder-14b-instruct-q4_k_m-00001-of-00002.gguf \

-ngl 20 \  # llm layers sent to GPU

-c 16384 \ # context window

--threads 8 \

--parallel 1 \

-ctk q8_0

-ctv q8_0

--flash-attn 'auto' \ # optimization function

--host 0.0.0.0 \

--port 8080

 

./llama-server -m /home/user/model/qwen2.5-coder-14b-instruct-GGUF/qwen2.5-coder-14b-instruct-q4_k_m-00001-of-00002.gguf -ngl 20 -c 66384 --threads 14 --parallel 1 -ctk q8_0 -ctv q8_0 --flash-attn 'auto' --host 0.0.0.0 --port 8080  --temp 1.0 --top-k 40 --top-p 0.95 --min-p 0

2.1. 32B

./llama-server -m /home/user/model/qwen2.5-coder-32b-instruct-GGUF/qwen2.5-coder-32b-instruct-q4_k_m.gguf -ngl 16 -c 66384 --threads 12 --parallel 1 -ctk q8_0 -ctv q8_0 --flash-attn 'auto' --host 0.0.0.0 --port 8080

2.2. 80B Qwen3-Coder-Next-GGUF. MOE model takes less resources then even 32B. 256k max context.

./llama-server -m /home/user/model/Qwen3-Coder-Next-GGUF/Qwen3-Coder-Next-Q4_K_M-00001-of-00004.gguf -ngl 7 -c 166384 --threads 12 --parallel 1 -ctk q8_0 -ctv q8_0 --flash-attn 'auto' --host 0.0.0.0 --port 8080 --temp 1.0 --top-k 40 --top-p 0.95 --min-p 0

2.3. GLM-4.7-Flash 30B-A3B Mixture-of-Experts (MoE) 

./llama-server -m /home/user/model/GLM-4.7-Flash/GLM-4.7-Flash.q4_k_m.gguf -ngl 16 -c 66384 --threads 12 --parallel 1 -ctk q8_0 -ctv q8_0 --flash-attn 'auto' --host 0.0.0.0 --port 8080 --temp 1.0 --top-k 40 --top-p 0.95 --min-p 0

 

TEST

1. First test Prompt

Create a new Python file rate_limiter.py and a test file test_rate_limiter.py. Implement a thread-safe Sliding Window Log rate limiter class SlidingWindowRateLimiter(max_requests: int, window_seconds: float) with a method allow_request(user_id: str) -> bool. Do not use external libraries—only standard library (time, threading, collections). Write comprehensive unittest cases covering: burst limits, window expiration, multiple independent users, zero/negative config validation, and concurrent threads hitting the limiter simultaneously. Run the test suite in the terminal and fix any failures.

1.1. Kimi estimated results:

7B  30/100

14B 25/100

32B 20/100

NEXT 80/100

GLM4.7 58/100

Ya plugin 88/100

GigaCode 90/100

 

2. Second task prompt:

Create cache.py and test_cache.py. Implement a thread-safe TTLCache class:

    TTLCache(maxsize: int, ttl_seconds: float)

with methods:

    get(key) -> value or None if missing/expired

    set(key, value) -> None; evicting the least-recently-used entry if at full capacity

    delete(key) -> bool (True if an entry was actually removed)

    size() -> int (number of live, unexpired entries)

Requirements:

- Thread-safe for concurrent get/set/delete from multiple threads (use threading primitives).

- O(1) average time per operation (use OrderedDict or a proper data structure; do NOT scan all entries on access).

- Entries expire ttl_seconds after being set. An expired entry must behave exactly like a missing one (get -> None, does not count toward size, its slot is reusable).

- Config validation: maxsize <= 0 or ttl_seconds <= 0 must raise ValueError.

- No external libraries. Standard library only (threading, collections, time, unittest, unittest.mock).

Tests must cover: basic set/get, overwrite of existing key, LRU eviction order (insert beyond capacity and verify WHO gets evicted), expiry (do NOT use real sleeping for the main expiry tests — inject or mock the clock so tests run instantly and deterministically; at most one test may use a short real sleep <= 0.2s), delete semantics, size() excluding expired entries, concurrent set/get from 20 threads producing no lost updates and a consistent final state, and invalid config.

 

2.1. Second estimation:

GigaCode (TTLCache) — 85/100

Ya - 94/100

Qwen3-next - 58/100

GLM-4.7-Flash 32/100

Qwen2.5-32B 52/100

Qwen2.5-14B 51/100

Qwen2.5-7B 33/100