From afd520f9a9b33dd6c87d07a97b3f5f6f77c8e92b Mon Sep 17 00:00:00 2001 From: cloveranon Date: Mon, 23 Dec 2019 04:15:20 -0500 Subject: [PATCH] uses gpu by default --- config.ini | 4 ++-- gpt2generator.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/config.ini b/config.ini index 0ba6480..28aa3f4 100644 --- a/config.ini +++ b/config.ini @@ -35,7 +35,7 @@ console-bell = on # Not sure of a good default but 80 was considered an ideal standard number of columns in old PCs. text-wrap-width = 80 -cpu = off +force-cpu = off log-level = 20 @@ -88,7 +88,7 @@ loading-message = 7;34 message=7;35 title = 31 subtitle = 36 -subsubtitle = 35 +subsubtitle = 36;7 instructions = 33 selection-prompt = 7;32 selection-value = 35 diff --git a/gpt2generator.py b/gpt2generator.py index 94c8ff0..2447879 100644 --- a/gpt2generator.py +++ b/gpt2generator.py @@ -7,6 +7,8 @@ from transformers import GPT2LMHeadModel, GPT2Tokenizer from getconfig import settings, logger from story.utils import cut_trailing_sentence +CPU = torch.cuda.is_available() and not settings.getboolean('force-cpu') + # warnings.filterwarnings("ignore") MODEL_CLASSES = { "gpt2": (GPT2LMHeadModel, GPT2Tokenizer), @@ -104,7 +106,7 @@ class GPT2Generator: self.top_p = top_p self.censor = censor self.samples = 1 - self.dtype = torch.float32 if settings.getboolean('cpu') else torch.float16 + self.dtype = torch.float32 if CPU else torch.float16 self.repetition_penalty = repetition_penalty self.batch_size = 1 self.stop_token = None @@ -112,7 +114,7 @@ class GPT2Generator: self.model_name = "pytorch-gpt2-xl-aid2-v5" self.model_dir = "models" self.checkpoint_path = os.path.join(self.model_dir, self.model_name) - self.device = torch.device("cuda" if torch.cuda.is_available() and not settings.getboolean('cpu') else "cpu") + self.device = torch.device("cuda" if not CPU else "cpu") logger.info("Using device={}, checkpoint={}".format(self.device, self.checkpoint_path)) # Load tokenizer and model