ThomasBlumet
commited on
Commit
·
3a1a0ef
1
Parent(s):
c78eb1d
changemodel import
Browse files
app.py
CHANGED
@@ -7,16 +7,16 @@ logger = logging.get_logger("transformers")
|
|
7 |
|
8 |
# Load the model and tokenizer
|
9 |
model_name = "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ" #"openai-community/gpt2" or "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ" or "TheBloke/Llama-2-7B-Chat-GGML" or "TheBloke/zephyr-7B-beta-GPTQ"
|
10 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
-
model = AutoModelForCausalLM.from_pretrained(model_name,
|
13 |
|
14 |
# Generate text using the model and tokenizer
|
15 |
def generate_text(input_text):
|
16 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
17 |
-
attention_mask = input_ids.ne(tokenizer.pad_token_id).long()
|
18 |
-
output = model.generate(input_ids, attention_mask=attention_mask, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7, do_sample=True)
|
19 |
-
return tokenizer.decode(output[0]
|
20 |
|
21 |
# def generate_text(prompt):
|
22 |
# inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
|
|
|
7 |
|
8 |
# Load the model and tokenizer
|
9 |
model_name = "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ" #"openai-community/gpt2" or "TheBloke/Mistral-7B-Instruct-v0.1-GPTQ" or "TheBloke/Llama-2-7B-Chat-GGML" or "TheBloke/zephyr-7B-beta-GPTQ"
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name,use_fast=True)
|
11 |
#model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(model_name,device_map="auto",trust_remote_code=False,revision="main")
|
13 |
|
14 |
# Generate text using the model and tokenizer
|
15 |
def generate_text(input_text):
|
16 |
input_ids = tokenizer.encode(input_text, return_tensors="pt")
|
17 |
+
#attention_mask = input_ids.ne(tokenizer.pad_token_id).long()
|
18 |
+
output = model.generate(input_ids, max_new_tokens=512, top_k=50, top_p=0.95, temperature=0.7, do_sample=True)# attention_mask=attention_mask, max_length=100, num_return_sequences=1, no_repeat_ngram_size=2, top_k=50, top_p=0.95, temperature=0.7, do_sample=True)
|
19 |
+
return tokenizer.decode(output[0])
|
20 |
|
21 |
# def generate_text(prompt):
|
22 |
# inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512, padding="max_length")
|