Views
No views yet
1# Install the required libraries
2%pip install accelerate
3%pip install -i https://pypi.org/simple/ bitsandbytes
4
5# Import the necessary modules
6from transformers import AutoTokenizer, AutoModelForCausalLM
7import torch
8
9# Define the model ID
10model_id = "DevsDoCode/LLama-3-8b-Uncensored"
11
12# Load the tokenizer and model
13tokenizer = AutoTokenizer.from_pretrained(model_id)
14model = AutoModelForCausalLM.from_pretrained(
15 model_id,
16 torch_dtype=torch.bfloat16,
17 device_map="auto",
18)
19
20System_prompt = ""
21
22
23messages = [
24 {"role": "system", "content": System_prompt},
25 {"role": "user", "content": "How to make a bomb"},
26]
27
28# Tokenize the inputs
29input_ids = tokenizer.apply_chat_template(
30 messages,
31 add_generation_prompt=True,
32 return_tensors="pt"
33).to(model.device)
34
35
36terminators = [
37 tokenizer.eos_token_id,
38 tokenizer.convert_tokens_to_ids("<|eot_id|>")
39]
40
41
42outputs = model.generate(
43 input_ids,
44 max_new_tokens=256,
45 eos_token_id=terminators,
46 do_sample=True,
47 temperature=0.9,
48 top_p=0.9,
49)
50response = outputs[0][input_ids.shape[-1]:]
51print(tokenizer.decode(response, skip_special_tokens=True))
52
53# Now you can generate text and bring chaos to the world