Views
No views yet
Transformers 4.56.0 are required to run the model.pip install -U transformerspip install git+https://github.com/rubber-duck-debug/xieluStaticLayer error, comment the arg prompt_lookup_num_tokens=None)1from unsloth import FastLanguageModel
2import torch
3
4# Load the model and tokenizer
5model, tokenizer = FastLanguageModel.from_pretrained(
6 model_name="safouaneelg/Apertus-8B-Instruct-2509-GSM8k-SFT",
7 max_seq_length=2048,
8 load_in_4bit=True,
9)
10
11# Move to device
12device = "cuda" if torch.cuda.is_available() else "cpu"
13
14# Example prompt from GSM8k
15prompt = "Short answer please. Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?."
16
17messages_think = [
18 {"role": "user", "content": prompt}
19]
20
21text = tokenizer.apply_chat_template(
22 messages_think,
23 tokenize=False,
24 add_generation_prompt=True,
25)
26model_inputs = tokenizer([text], return_tensors="pt", add_special_tokens=False).to(model.device)
27
28outputs = model.generate(
29 **model_inputs,
30 max_new_tokens=256,
31 temperature=0.8,
32 top_p=0.9,
33 use_cache=True,
34 do_sample=True,
35 prompt_lookup_num_tokens=None #for some reasoning this sometimes solve the inferencing errors
36)
37
38generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
39print(generated_text)1import os
2from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
3
4model_name = "safouaneelg/Apertus-8B-Instruct-2509-GSM8k-SFT"
5device = "cuda" if torch.cuda.is_available() else "cpu"
6
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForCausalLM.from_pretrained(
9 model_name,
10).to(device)
11
12# prepare the model input
13prompt = "Short answer please. Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May?"
14messages_think = [
15 {"role": "user", "content": prompt}
16]
17
18text = tokenizer.apply_chat_template(
19 messages_think,
20 tokenize=False,
21 add_generation_prompt=True,
22)
23
24streamer = TextStreamer(tokenizer)
25
26model_inputs = tokenizer([text], return_tensors="pt", add_special_tokens=False).to(model.device)
27
28# Generate the output
29generated_ids = model.generate(**model_inputs, streamer=streamer, max_new_tokens=2024)
30
31# Get and decode the output
32output_ids = generated_ids[0][len(model_inputs.input_ids[0]) :]
33print(tokenizer.decode(output_ids, skip_special_tokens=True))
cmake-4.1.1-linux-x86_64.sh.1sudo cp cmake-4.1.1-linux-x86_64.sh /opt/
2sudo chmod +x cmake-4.1.1-linux-x86_64.shCUDA_HOME=/usr/local/cudaX.X1export PATH="/opt/cmake-4.1.1-linux-x86_64/bin:$PATH"
2export CUDA_HOME=/usr/local/cuda
3export PATH=$CUDA_HOME/bin:$PATH
4export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH1source ~/.bashrc
2# or
3source ~/.zshrcnvcc --version to confirm that the CUDA compiler is now in your PATH. You should see the CUDA version number. And, run echo $CUDA_HOME to confirm that the environment variable is set correctly.pip install git+https://github.com/rubber-duck-debug/xielu.1@misc{swissai2025apertus,
2 title={{Apertus: Democratizing Open and Compliant LLMs for Global Language Environments}},
3 author={Apertus Team},
4 year={2025},
5 howpublished={\url{https://huggingface.co/swiss-ai/Apertus-8B-Instruct-2509}}
6}