Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gen_kwargs = {
|
2 |
+
"max_new_tokens": 100,
|
3 |
+
"top_k": 70,
|
4 |
+
"top_p": 0.8,
|
5 |
+
"do_sample": True,
|
6 |
+
"no_repeat_ngram_size": 2,
|
7 |
+
"bos_token_id": tokenizer.bos_token_id,
|
8 |
+
"eos_token_id": tokenizer.eos_token_id,
|
9 |
+
"pad_token_id": tokenizer.pad_token_id,
|
10 |
+
"temperature": 0.8,
|
11 |
+
"use_cache": True,
|
12 |
+
"repetition_penalty": 1.2,
|
13 |
+
"num_return_sequences": 1
|
14 |
+
}
|
15 |
+
device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
|
16 |
+
ft = 'gpt-j-onlyk_v2'
|
17 |
+
tokenizer = AutoTokenizer.from_pretrained(ft)
|
18 |
+
model = AutoModelForCausalLM.from_pretrained(ft, torch_dtype=torch.float16, low_cpu_mem_usage=True)
|
19 |
+
model.to(device)
|
20 |
+
|
21 |
+
prepared = tokenizer.encode(inp, return_tensors='pt').to(model.device)
|
22 |
+
out = model.generate(input_ids=prepared, **gen_kwargs)
|
23 |
+
generated = tokenizer.decode(out[0])
|