Views
No views yet
pip install transformers accelerate torch bitsandbytes peft 1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2import torch
3from peft import PeftModel, PeftConfig
4
5read_token="YOUR HUGGINGFACE TOKEN"
6
7nf4_config = BitsAndBytesConfig(
8 load_in_4bit=True,
9 bnb_4bit_quant_type="nf4",
10 bnb_4bit_use_double_quant=True,
11 bnb_4bit_compute_dtype=torch.bfloat16
12)
13
14model = AutoModelForCausalLM.from_pretrained(
15 "mistralai/Mistral-7B-Instruct-v0.2",
16 device_map='auto',
17 quantization_config=nf4_config,
18 use_cache=False,
19 token=read_token
20)
21
22
23model = PeftModel.from_pretrained(model, "pranay-j/mistral-7b-nl2bash-agent",device_map='auto',token=read_token)
24
25tokenizer=AutoTokenizer.from_pretrained("pranay-j/mistral-7b-nl2bash-agent",add_eos_token=False)
26nl='Add "execute" to the permissions of all directories in the home directory tree'
27prompt= f"[INST] {nl} [/INST]"
28
29inputs=tokenizer(prompt,return_tensors="pt")
30input_ids=inputs["input_ids"].to("cuda")
31
32with torch.no_grad():
33 out=model.generate(input_ids,top_p=0.5, temperature=0.7, max_new_tokens=30)
34
35tokenizer.decode(out[0][input_ids.shape[-1]:])
36# Output: find ~ -type d -exec chmod +x {} </s>| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 1.6136 | 1.0 | 202 | 1.6451 |
| 1.5448 | 2.0 | 404 | 1.5952 |