From 8b5335fb7e359246f26f20a0426c51284be79f91 Mon Sep 17 00:00:00 2001 From: William-Gazeley Date: Tue, 19 Mar 2024 15:08:02 +0800 Subject: [PATCH] Allow benchmarking on CPU --- fingpt/FinGPT_Benchmark/benchmarks/fiqa.py | 2 +- fingpt/FinGPT_Benchmark/benchmarks/fpb.py | 2 +- fingpt/FinGPT_Benchmark/benchmarks/nwgi.py | 2 +- fingpt/FinGPT_Benchmark/benchmarks/tfns.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fingpt/FinGPT_Benchmark/benchmarks/fiqa.py b/fingpt/FinGPT_Benchmark/benchmarks/fiqa.py index 1967b82..e9cd311 100644 --- a/fingpt/FinGPT_Benchmark/benchmarks/fiqa.py +++ b/fingpt/FinGPT_Benchmark/benchmarks/fiqa.py @@ -87,7 +87,7 @@ def test_fiqa(args, model, tokenizer, prompt_fun=add_instructions): tokens = tokenizer(tmp_context, return_tensors='pt', padding=True, max_length=512, return_token_type_ids=False) # tokens.pop('token_type_ids') for k in tokens.keys(): - tokens[k] = tokens[k].cuda() + tokens[k] = tokens[k].to(model.device) res = model.generate(**tokens, max_length=512, eos_token_id=tokenizer.eos_token_id) res_sentences = [tokenizer.decode(i, skip_special_tokens=True) for i in res] diff --git a/fingpt/FinGPT_Benchmark/benchmarks/fpb.py b/fingpt/FinGPT_Benchmark/benchmarks/fpb.py index 1a460a3..c4d21c1 100644 --- a/fingpt/FinGPT_Benchmark/benchmarks/fpb.py +++ b/fingpt/FinGPT_Benchmark/benchmarks/fpb.py @@ -82,7 +82,7 @@ def test_fpb(args, model, tokenizer, prompt_fun=None): tmp_context = context[i* batch_size:(i+1)* batch_size] tokens = tokenizer(tmp_context, return_tensors='pt', padding=True, max_length=512, return_token_type_ids=False) for k in tokens.keys(): - tokens[k] = tokens[k].cuda() + tokens[k] = tokens[k].to(model.device) res = model.generate(**tokens, max_length=512, eos_token_id=tokenizer.eos_token_id) res_sentences = [tokenizer.decode(i, skip_special_tokens=True) for i in res] # print(f'{i}: {res_sentences[0]}') diff --git a/fingpt/FinGPT_Benchmark/benchmarks/nwgi.py b/fingpt/FinGPT_Benchmark/benchmarks/nwgi.py index ced2b5b..ef2a483 100644 --- a/fingpt/FinGPT_Benchmark/benchmarks/nwgi.py +++ b/fingpt/FinGPT_Benchmark/benchmarks/nwgi.py @@ -65,7 +65,7 @@ def test_nwgi(args, model, tokenizer, prompt_fun=None): tokens = tokenizer(tmp_context, return_tensors='pt', padding=True, max_length=512, return_token_type_ids=False) # tokens.pop('token_type_ids') for k in tokens.keys(): - tokens[k] = tokens[k].cuda() + tokens[k] = tokens[k].to(model.device) res = model.generate(**tokens, max_length=512, eos_token_id=tokenizer.eos_token_id) res_sentences = [tokenizer.decode(i, skip_special_tokens=True) for i in res] out_text = [o.split("Answer: ")[1] for o in res_sentences] diff --git a/fingpt/FinGPT_Benchmark/benchmarks/tfns.py b/fingpt/FinGPT_Benchmark/benchmarks/tfns.py index 8c7ae84..b2a2df9 100644 --- a/fingpt/FinGPT_Benchmark/benchmarks/tfns.py +++ b/fingpt/FinGPT_Benchmark/benchmarks/tfns.py @@ -61,7 +61,7 @@ def test_tfns(args, model, tokenizer, prompt_fun=None): tokens = tokenizer(tmp_context, return_tensors='pt', padding=True, max_length=512, return_token_type_ids=False) # tokens.pop('token_type_ids') for k in tokens.keys(): - tokens[k] = tokens[k].cuda() + tokens[k] = tokens[k].to(model.device) res = model.generate(**tokens, max_length=512, eos_token_id=tokenizer.eos_token_id) res_sentences = [tokenizer.decode(i, skip_special_tokens=True) for i in res] out_text = [o.split("Answer: ")[1] for o in res_sentences]