Skip to content
This repository was archived by the owner on Dec 2, 2025. It is now read-only.

Commit a2141cd

Browse files
Merge branch 'Develop' into sfw
2 parents 966a8eb + 6b76d8d commit a2141cd

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

server/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
#--
4848
#-- 23/01/2024 Lyaaaaa
4949
#-- - Removed TOKENIZERS_PATH.
50+
#--
51+
#-- 08/05/2024 Lyaaaaa
52+
#-- - Added TORCH_DTYPE_SAFETY.
5053
#---------------------------------------------------------------------------
5154

5255
import logging
@@ -79,3 +82,5 @@
7982
DEVICE_MAP = None # None/see documentation
8083
TORCH_DTYPE = None # "Auto"/None/torch.dtype/See torch_dtype.py for more info.
8184

85+
# Safeguards
86+
TORCH_DTYPE_SAFETY = True # True/False. If CUDA isn't available, will enforce Torch_Dtype to float32 to avoir error. See issue https://github.com/LyaaaaaGames/AIdventure_Server/issues/31

server/model.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,16 @@
203203
#-- - Added a log message to display the model's name and its path.
204204
#-- - Added a log message to display if cuda is supported.
205205
#--
206+
#--
206207
#-- - 07/05/2024 Lyaaaaa
207208
#-- - Updated _load_tokens to set add_prefix_space to True. It is needed
208209
#-- for using bad_words_ids parameter for generation.
210+
#--
211+
#-- - 08/05/2024 Lyaaaaa
212+
#-- - Updated _load_model to force (if config.TORCH_DTYPE_SAFETY is True)
213+
#-- torch_dtype to be set to float32 if cuda isn't available.
214+
#-- Because otherwise, it will lead to an error during generation.
215+
#-- See https://github.com/LyaaaaaGames/AIdventure_Server/issues/31
209216
#------------------------------------------------------------------------------
210217

211218
from transformers import AutoModelForCausalLM, AutoModelForSeq2SeqLM, AutoTokenizer
@@ -327,6 +334,11 @@ def _load_model(self):
327334
logger.log.debug("Model settings:")
328335
logger.log.debug(args)
329336

337+
if not self.is_cuda_available and config.TORCH_DTYPE_SAFETY:
338+
logger.log.warn("Cuda isn't available.")
339+
logger.log.warn("Setting torch_dtype to float 32 to avoid error.")
340+
args["torch_dtype"] = Torch_Dtypes.dtypes.value[Torch_Dtypes.FLOAT_32.value]
341+
330342
self._Model = AutoModelForCausalLM.from_pretrained(self._model_path,
331343
**args)
332344
except Exception as e:

0 commit comments

Comments
 (0)