added usage code
Browse files
README.md
CHANGED
@@ -33,6 +33,51 @@ Mistral 7B NL2BASH Agent is a fine-tuned model that converts natural language qu
|
|
33 |
- The model's performance may vary based on the complexity and specificity of the natural language queries.
|
34 |
- It may not handle all edge cases or uncommon scenarios effectively.
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
## Training and evaluation data
|
37 |
|
38 |
More information needed
|
|
|
33 |
- The model's performance may vary based on the complexity and specificity of the natural language queries.
|
34 |
- It may not handle all edge cases or uncommon scenarios effectively.
|
35 |
|
36 |
+
## Installation
|
37 |
+
```bash
|
38 |
+
pip install transformers accelerate torch bitsandbytes peft
|
39 |
+
```
|
40 |
+
|
41 |
+
## Usage
|
42 |
+
```python
|
43 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
44 |
+
import torch
|
45 |
+
from peft import PeftModel, PeftConfig
|
46 |
+
|
47 |
+
read_token="YOUR HUGGINGFACE TOKEN"
|
48 |
+
|
49 |
+
nf4_config = BitsAndBytesConfig(
|
50 |
+
load_in_4bit=True,
|
51 |
+
bnb_4bit_quant_type="nf4",
|
52 |
+
bnb_4bit_use_double_quant=True,
|
53 |
+
bnb_4bit_compute_dtype=torch.bfloat16
|
54 |
+
)
|
55 |
+
|
56 |
+
model = AutoModelForCausalLM.from_pretrained(
|
57 |
+
"mistralai/Mistral-7B-Instruct-v0.2",
|
58 |
+
device_map='auto',
|
59 |
+
quantization_config=nf4_config,
|
60 |
+
use_cache=False,
|
61 |
+
token=read_token
|
62 |
+
)
|
63 |
+
|
64 |
+
|
65 |
+
model = PeftModel.from_pretrained(model, "pranay-j/mistral-7b-nl2bash-agent",device_map='auto',token=read_token)
|
66 |
+
|
67 |
+
tokenizer=AutoTokenizer.from_pretrained("pranay-j/mistral-7b-nl2bash-agent",add_eos_token=False)
|
68 |
+
nl='Add "execute" to the permissions of all directories in the home directory tree'
|
69 |
+
prompt= f"[INST] {nl} [/INST]"
|
70 |
+
|
71 |
+
inputs=tokenizer(prompt,return_tensors="pt")
|
72 |
+
input_ids=inputs["input_ids"].to("cuda")
|
73 |
+
|
74 |
+
with torch.no_grad():
|
75 |
+
out=model.generate(input_ids,top_p=0.5, temperature=0.7, max_new_tokens=30)
|
76 |
+
|
77 |
+
tokenizer.decode(out[0][input_ids.shape[-1]:])
|
78 |
+
# Output: find ~ -type d -exec chmod +x {} </s>
|
79 |
+
```
|
80 |
+
|
81 |
## Training and evaluation data
|
82 |
|
83 |
More information needed
|