File size: 2,026 Bytes
5b94f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
pretty_name: Qwen3-8B Algorithmic Code Analyzer
base_model: Qwen/Qwen3-8B
base_model_relation: finetune
library_name: transformers
pipeline_tag: text-generation
language:
- en
tags:
- competitive-programming
- cpp
- algorithm-explanation
- code-understanding
- lora
- experimental
- codeforces
- leetcode
datasets:
- orucexe/algorithmic-code-understanding
license: apache-2.0
---

# Qwen3-8B Algorithmic Code Analyzer

Experimental Qwen3-8B fine-tune for exploring **C++ code explanations, algorithm ideas, invariants, complexity and explanation checking**.
Trained on 3,613 [problem → code + analysis examples](https://huggingface.co/datasets/orucexe/algorithmic-code-understanding); supplied-code analysis is an exploratory use.

## Usage

```bash
pip install "transformers>=4.51,<5" accelerate torch
```

```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

repo = "orucexe/Qwen3-8B-Algorithmic-Code-Analyzer"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(
    repo, torch_dtype="auto", device_map="auto"
).eval()

prompt = """Explain what this C++ code computes, its core idea,
loop invariant, time and auxiliary-space complexity, and edge cases.
Do not rewrite the code.

long long sum(const std::vector<int>& a) {
    long long s = 0;
    for (int x : a) s += x;
    return s;
}
"""
inputs = tokenizer.apply_chat_template(
    [{"role": "user", "content": prompt}],
    add_generation_prompt=True, enable_thinking=False,
    return_dict=True, return_tensors="pt"
).to(model.device)
with torch.inference_mode():
    output = model.generate(
        **inputs, max_new_tokens=1024, do_sample=True,
        temperature=0.7, top_p=0.8, top_k=20,
        pad_token_id=tokenizer.eos_token_id
    )
print(tokenizer.decode(output[0, inputs.input_ids.shape[1]:], skip_special_tokens=True))
```

For thinking mode, set `enable_thinking=True`, `temperature=0.6`, `top_p=0.95` ([Qwen guidance](https://huggingface.co/Qwen/Qwen3-8B#best-practices)).