Update install stuff
This commit is contained in:
parent
f082ef696c
commit
25b12a512d
3 changed files with 21 additions and 12 deletions
|
|
@ -8,17 +8,16 @@ import argparse
|
||||||
from typing import List, Dict, Tuple, Any, Optional
|
from typing import List, Dict, Tuple, Any, Optional
|
||||||
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
|
||||||
from huggingface_hub import login
|
from huggingface_hub import login
|
||||||
from llm_attacks.minimal_gcg.opt_utils import get_filtered_cands
|
|
||||||
from words import words
|
from words import words
|
||||||
from utils import (
|
from utils import (
|
||||||
minimize_tokens,
|
minimize_tokens,
|
||||||
sample_control,
|
sample_control,
|
||||||
count_tokens,
|
count_tokens,
|
||||||
get_combined_score,
|
|
||||||
get_random_words,
|
get_random_words,
|
||||||
token_gradients_combined,
|
token_gradients_combined,
|
||||||
find_best_word_to_add,
|
find_best_word_to_add,
|
||||||
words_db,
|
words_db,
|
||||||
|
get_filtered_cands,
|
||||||
)
|
)
|
||||||
|
|
||||||
# check if cuda is available
|
# check if cuda is available
|
||||||
|
|
|
||||||
|
|
@ -3,22 +3,15 @@ conda init
|
||||||
conda create --name prompt-guard python=3.12 -c conda-forge
|
conda create --name prompt-guard python=3.12 -c conda-forge
|
||||||
conda activate prompt-guard
|
conda activate prompt-guard
|
||||||
|
|
||||||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
|
|
||||||
rustup install 1.82
|
|
||||||
rustup default 1.82
|
|
||||||
|
|
||||||
pip install fschat
|
|
||||||
#cuda
|
#cuda
|
||||||
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
|
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
|
||||||
|
|
||||||
#or cpu
|
#or cpu
|
||||||
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
pip install torch --index-url https://download.pytorch.org/whl/cpu
|
||||||
|
|
||||||
pip install -U "huggingface_hub[cli]"
|
pip install -U "huggingface_hub[cli]"
|
||||||
# install transformers
|
# install transformers
|
||||||
pip install transformers
|
pip install -U transformers
|
||||||
export RUSTFLAGS="-A invalid_reference_casting"
|
pip install -U tiktoken
|
||||||
pip install git+https://github.com/llm-attacks/llm-attacks
|
|
||||||
|
|
||||||
huggingface-cli login
|
huggingface-cli login
|
||||||
pip install -U transformers
|
|
||||||
|
|
|
||||||
17
utils.py
17
utils.py
|
|
@ -644,3 +644,20 @@ def get_combined_score(
|
||||||
best_idx = idx
|
best_idx = idx
|
||||||
|
|
||||||
return best_idx
|
return best_idx
|
||||||
|
|
||||||
|
def get_filtered_cands(tokenizer, control_cand, filter_cand=True, curr_control=None):
|
||||||
|
cands, count = [], 0
|
||||||
|
for i in range(control_cand.shape[0]):
|
||||||
|
decoded_str = tokenizer.decode(control_cand[i], skip_special_tokens=True)
|
||||||
|
if filter_cand:
|
||||||
|
if decoded_str != curr_control and len(tokenizer(decoded_str, add_special_tokens=False).input_ids) == len(control_cand[i]):
|
||||||
|
cands.append(decoded_str)
|
||||||
|
else:
|
||||||
|
count += 1
|
||||||
|
else:
|
||||||
|
cands.append(decoded_str)
|
||||||
|
|
||||||
|
if filter_cand:
|
||||||
|
cands = cands + [cands[-1]] * (len(control_cand) - len(cands))
|
||||||
|
# print(f"Warning: {round(count / len(control_cand), 2)} control candidates were not valid")
|
||||||
|
return cands
|
||||||
Loading…
Add table
Add a link
Reference in a new issue