Views
No views yet
verdict: 'OK'. This model only learns from code that works.unsloth/llama-3.1-8b-instruct-bnb-4bit - A powerful and modern foundation.1from unsloth import FastLanguageModel
2import torch
3
4# The original base model
5base_model_name = "unsloth/llama-3.1-8b-Instruct-bnb-4bit"
6
7# STEP 1: Load the base model and tokenizer
8model, tokenizer = FastLanguageModel.from_pretrained(
9 model_name = base_model_name,
10 max_seq_length = 4096,
11 dtype = None,
12 load_in_4bit = True,
13)
14
15# STEP 2: Apply your fine-tuned adapters from the Hub
16# This is where you load Soltra's brain
17model = FastLanguageModel.from_pretrained(
18 model = model,
19 model_name = "Redhanuman/soltra-llama-3.1-8b-cpp-adapters", # Your repo on the Hub
20)
21
22# --- Now, run inference ---
23# The prompt must be in the same format the model was trained on.
24prompt = """<|begin_of_text|><|start_header_id|>user<|end_header_id|>
25
26Solve this competitive programming problem by providing a step-by-step thought process and then the final code.
27
28**Problem:** C. Registration System
29**Rating:** 1500
30**Tags:** data structures, strings, maps
31
32**Problem Statement:**
33A new user registration system is being developed. When a new user wants to register, they enter a desired username. If this name is not already in the database, it's added, and the user receives an "OK" message. If the name is already taken, the system appends a number to the name to make it unique. The first time a name is duplicated, it appends '1', the second time '2', and so on. Given a sequence of username registration attempts, output the system's response for each.
34
35**Provide:**
361. **Thought Process:** A brief explanation of the logic, data structures, and algorithm used.
372. **C++ Solution:** An efficient and correct solution in C++.<|eot_id|><|start_header_id|>assistant<|end_header_id|>"""
38
39inputs = tokenizer([prompt], return_tensors="pt", truncation=False).to("cuda")
40
41# Generate the response
42with torch.no_grad():
43 outputs = model.generate(**inputs, max_new_tokens=512, use_cache=True)
44response = tokenizer.batch_decode(outputs)
45
46# Print the generated part of the response
47print(response[0].split("<|start_header_id|>assistant<|end_header_id|>")[1].replace("<|eot_id|>", "").strip())