Skip to content

Commit fd5fa73

Browse files
authored
fix mindspore2.5-2.6 caused error (#1985)
1 parent 93c0d75 commit fd5fa73

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

llm/inference/llama2/simple_inference_with_static_cache.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ def decode_one_tokens(model, cur_token, input_pos, cache_position, past_key_valu
4545
generated_ids[:, seq_length] = next_token[:, 0]
4646

4747
cache_position = mindspore.tensor([seq_length + 1])
48+
s = time.time()
4849
for _ in range(1, NUM_TOKENS_TO_GENERATE):
49-
s = time.time()
5050
next_token = decode_one_tokens(model, next_token, None, cache_position, past_key_values)
51-
t = time.time()
52-
print(t - s)
5351
generated_ids[:, cache_position] = next_token.int()
5452
cache_position += 1
53+
mindspore.hal.synchronize()
54+
t = time.time()
55+
print((t - s) / (NUM_TOKENS_TO_GENERATE - 1))
5556

5657
text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
5758
print(text)

llm/inference/llama3/run_llama3.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import mindspore
22
from mindnlp.transformers import AutoTokenizer, AutoModelForCausalLM
3+
import faulthandler
4+
5+
faulthandler.enable()
36

47
model_id = "LLM-Research/Meta-Llama-3-8B-Instruct"
58

mindnlp/core/ops/other.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from mindspore.common.initializer import initializer
77
from mindspore.ops._primitive_cache import _get_cache_prim
88

9-
from mindnlp.configs import use_pyboost, ON_ORANGE_PI
9+
from mindnlp.configs import use_pyboost, ON_ORANGE_PI, SUPPORT_BF16
1010
from .reduction import any
1111
from .comparison import eq
1212

@@ -623,12 +623,12 @@ def meshgrid(*tensors, indexing=None):
623623
# repeat_interleave
624624
has_repeat_interleave = hasattr(mindspore.mint, 'repeat_interleave')
625625
def repeat_interleave(input, repeats, dim=None):
626-
if use_pyboost() and has_repeat_interleave:
626+
if use_pyboost() and has_repeat_interleave and SUPPORT_BF16:
627627
return mindspore.mint.repeat_interleave(input, repeats, dim=dim)
628628
if input.dtype == mindspore.bool_:
629629
input = input.int()
630-
return input.repeat(repeats, dim).bool()
631-
return input.repeat(repeats, dim)
630+
return input.repeat_interleave(repeats, dim).bool()
631+
return input.repeat_interleave(repeats, dim)
632632

633633
# roll
634634
DEVICE_TARGET = mindspore.get_context('device_target')

mindnlp/core/serialization.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,8 +1412,7 @@ def convert(info: dict[str, Any]):
14121412

14131413
try:
14141414
if info['dtype'] == 'BF16' and not SUPPORT_BF16:
1415-
logger.warning_once("MindSpore do not support bfloat16 dtype, we will automaticlly convert to float16")
1416-
ms_dtype = mindspore.float16
1415+
raise ValueError('not support bfloat16.')
14171416
out = Tensor.convert_bytes_to_tensor(buf, tuple(shape), ms_dtype)
14181417
except:
14191418
array = np.frombuffer(buf, dtype=numpy_dtype).reshape(shape)

0 commit comments

Comments
 (0)