jiacheng-ye/nl2bash
Viewer • Updated • 9.31k • 317 • 16
How to use pranay-j/mistral-7b-nl2bash-agent with PEFT:
from peft import PeftModel
from transformers import AutoModelForCausalLM
base_model = AutoModelForCausalLM.from_pretrained("mistralai/Mistral-7B-Instruct-v0.2")
model = PeftModel.from_pretrained(base_model, "pranay-j/mistral-7b-nl2bash-agent")This model is a fine-tuned version of mistralai/Mistral-7B-Instruct-v0.2 on the nl2bash dataset. It achieves the following results on the evaluation set:
Mistral 7B NL2BASH Agent is a fine-tuned model that converts natural language queries into Linux commands. It serves as an intelligent agent capable of generating Linux commands based on user input in the form of natural language queries.
pip install transformers accelerate torch bitsandbytes peft
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
import torch
from peft import PeftModel, PeftConfig
read_token="YOUR HUGGINGFACE TOKEN"
nf4_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.bfloat16
)
model = AutoModelForCausalLM.from_pretrained(
"mistralai/Mistral-7B-Instruct-v0.2",
device_map='auto',
quantization_config=nf4_config,
use_cache=False,
token=read_token
)
model = PeftModel.from_pretrained(model, "pranay-j/mistral-7b-nl2bash-agent",device_map='auto',token=read_token)
tokenizer=AutoTokenizer.from_pretrained("pranay-j/mistral-7b-nl2bash-agent",add_eos_token=False)
nl='Add "execute" to the permissions of all directories in the home directory tree'
prompt= f"[INST] {nl} [/INST]"
inputs=tokenizer(prompt,return_tensors="pt")
input_ids=inputs["input_ids"].to("cuda")
with torch.no_grad():
out=model.generate(input_ids,top_p=0.5, temperature=0.7, max_new_tokens=30)
tokenizer.decode(out[0][input_ids.shape[-1]:])
# Output: find ~ -type d -exec chmod +x {} </s>
More information needed
The following hyperparameters were used during training:
| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 1.6136 | 1.0 | 202 | 1.6451 |
| 1.5448 | 2.0 | 404 | 1.5952 |
Base model
mistralai/Mistral-7B-Instruct-v0.2