From 76e01fd437d133ac4d2c99e0c5a3094c21da3f17 Mon Sep 17 00:00:00 2001 From: AndyVerne <651264571@qq.com> Date: Fri, 6 Dec 2024 17:44:42 +0800 Subject: [PATCH] [fix] Update layerwise.py: avoid forced type conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During layerwise model initialization, if both use_bf16 and use_fp16 are set to false, use_fp16 is forcibly converted to true. However, in some scenarios, the warning’s granularity does not propagate to the Python terminal, causing users to overlook this implicit behavior and potentially introducing unexpected bugs. Therefore, I have committed a version of the code that explicitly notifies the user of incorrect input parameters, making it more aligned with everyday usage. --- 在layerwise模型相关初始化时,当use_bf16和 use_fp16都为false时,use_fp16会被强制转换成true;然而在一些场景,warning的告警粒度传递不到python terminal中,让人关注不到这一隐性的情况,从而可能产生预期之外的bug。 因此commit一版代码,强制告知user传入参数有误,更符合日常使用。 --- FlagEmbedding/inference/reranker/decoder_only/layerwise.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FlagEmbedding/inference/reranker/decoder_only/layerwise.py b/FlagEmbedding/inference/reranker/decoder_only/layerwise.py index 9a3e2301..f456b050 100644 --- a/FlagEmbedding/inference/reranker/decoder_only/layerwise.py +++ b/FlagEmbedding/inference/reranker/decoder_only/layerwise.py @@ -111,8 +111,7 @@ def __init__( ) if use_bf16 is False and use_fp16 is False: - warnings.warn("Due to model constraints, `use_bf16` and `use_fp16` cannot both be `False`. Here, `use_fp16` is set to `True` by default.", UserWarning) - self.use_fp16 = True + raise ValueError("Due to model constraints, Both use_bf16 and use_fp16 cannot be False. Please set at least one to True.") try: self.model = LayerWiseMiniCPMForCausalLM.from_pretrained(