Views
No views yet

Run the code below to run ICONN 1 Mini Beta:
1import os
2
3import torch
4
5from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
6
7from threading import Thread
8
9
10
11model_id = "ICONNAI/ICONN-1-Mini-Beta"
12
13
14
15try:
16
17model = AutoModelForCausalLM.from_pretrained(
18
19model_id, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True
20
21)
22
23tokenizer = AutoTokenizer.from_pretrained(model_id)
24
25except Exception as e:
26
27exit(f"Exiting due to model loading error: {e}")
28
29
30
31def generate_response(
32
33message: str,
34
35max_new_tokens: int = 2048,
36
37temperature: float = 0.4,
38
39top_p: float = 0.9,
40
41top_k: int = 50,
42
43repetition_penalty: float = 1.2,
44
45) -> str:
46
47conversation = [{"role": "user", "content": message}]
48
49
50
51try:
52
53input_ids = tokenizer.apply_chat_template(
54
55conversation, return_tensors="pt", enable_thinking=True
56
57)
58
59except Exception as e:
60
61return f"Error applying chat template: {e}"
62
63
64
65input_ids = input_ids.to(model.device)
66
67
68
69streamer = TextIteratorStreamer(tokenizer, timeout=20.0, skip_prompt=True, skip_special_tokens=True)
70
71
72
73adjusted_top_k = int(max(1, top_k))
74
75
76
77generate_kwargs = dict(
78
79{"input_ids": input_ids},
80
81streamer=streamer,
82
83max_new_tokens=max_new_tokens,
84
85do_sample=True,
86
87top_p=top_p,
88
89top_k=adjusted_top_k,
90
91temperature=temperature,
92
93num_beams=1,
94
95repetition_penalty=repetition_penalty,
96
97)
98
99
100
101try:
102
103t = Thread(target=model.generate, kwargs=generate_kwargs)
104
105t.start()
106
107except Exception as e:
108
109return f"Error starting generation thread: {e}"
110
111
112
113outputs = []
114
115for text in streamer:
116
117outputs.append(text)
118
119return "".join(outputs)
120
121
122
123if __name__ == "__main__":
124
125question = "Can you explain briefly to me what is the Python programming language?"
126
127print(f"User Question: {question}")
128
129
130
131response = generate_response(question)
132
133print(f"Bot Response: {response}")1
2@misc{iconnai_2025,
3 author = { ICONNAI },
4 title = { ICONN-1-Mini-Beta (Revision e29b435) },
5 year = 2025,
6 url = { https://huggingface.co/ICONNAI/ICONN-1-Mini-Beta },
7 doi = { 10.57967/hf/5860 },
8 publisher = { Hugging Face }
9}
10