Views
No views yet

eryk-mazus/polka-1.1b-chat is the first polish model trained to act as a helpful, conversational assistant that can be run locally.1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer
3
4model_name = "eryk-mazus/polka-1.1b-chat"
5
6tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
7tokenizer.pad_token = tokenizer.eos_token
8
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 torch_dtype=torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float16,
12 device_map="auto"
13)
14streamer = TextStreamer(tokenizer, skip_prompt=True)
15
16# You are a helpful assistant.
17system_prompt = "Jesteś pomocnym asystentem."
18chat = [{"role": "system", "content": system_prompt}]
19
20# Compose a short song on programming.
21user_input = "Napisz krótką piosenkę o programowaniu."
22chat.append({"role": "user", "content": user_input})
23
24# Generate - add_generation_prompt to make sure it continues as assistant
25inputs = tokenizer.apply_chat_template(chat, add_generation_prompt=True, return_tensors="pt")
26# For multi-GPU, find the device of the first parameter of the model
27first_param_device = next(model.parameters()).device
28inputs = inputs.to(first_param_device)
29
30with torch.no_grad():
31 outputs = model.generate(
32 inputs,
33 pad_token_id=tokenizer.eos_token_id,
34 max_new_tokens=512,
35 temperature=0.2,
36 repetition_penalty=1.15,
37 top_p=0.95,
38 do_sample=True,
39 streamer=streamer,
40 )
41
42# Add just the new tokens to our chat
43new_tokens = outputs[0, inputs.size(1):]
44response = tokenizer.decode(new_tokens, skip_special_tokens=True)
45chat.append({"role": "assistant", "content": response})<|im_start|>system
Jesteś pomocnym asystentem.
<|im_start|>user
Jakie jest dzienne zapotrzebowanie kaloryczne dorosłej osoby?<|im_end|>
<|im_start|>assistant
Dla dorosłych osób zaleca się spożywanie około 2000-3000 kcal dziennie, aby utrzymać optymalne zdrowie i dobre samopoczucie.<|im_end|>tokenizer.apply_chat_template() method, as demonstrated in the example above.