Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "TypeError: Got unsupported ScalarType BFloat16" #2472

Merged
merged 1 commit into from
Sep 18, 2024

Conversation

SeitaroShinagawa
Copy link
Contributor

Motivation

This PR is to solve the following issue,

Modification

Following the discussion in the above issue, I just modified one line as follows,
https://github.com/InternLM/lmdeploy/blob/main/lmdeploy/serve/utils.py#L219

_logits = _logits.cpu()
-> _logits = _logits.float().cpu()

How it works

I tried the same code introduced in #2453 and confirmed it works well.

$ ipython
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.15.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from transformers import AutoTokenizer
   ...: from lmdeploy import pipeline
   ...: model_repoid_or_path='internlm/internlm2_5-7b-chat'
   ...: pipe = pipeline(model_repoid_or_path)
   ...: tokenizer = AutoTokenizer.from_pretrained(model_repoid_or_path, trust_remote_code=True)
   ...: 
   ...: # logits
   ...: messages = [
   ...:    {"role": "user", "content": "Hello, how are you?"},
   ...: ]
   ...: input_ids = tokenizer.apply_chat_template(messages)
   ...: logits = pipe.get_logits(input_ids)
   ...: 
   ...: # ppl
   ...: ppl = pipe.get_ppl(input_ids)
Fetching 20 files: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:00<00:00, 273244.56it/s]

In [2]: ppl
Out[2]: array([4.489496], dtype=float32)

@lvhan028 lvhan028 requested a review from irexyc September 18, 2024 06:34
@lvhan028 lvhan028 changed the title fix [Bug] TypeError: Got unsupported ScalarType BFloat16 Fix "TypeError: Got unsupported ScalarType BFloat16" Sep 18, 2024
@lvhan028 lvhan028 merged commit 4305ddf into InternLM:main Sep 18, 2024
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants