You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug/ 问题描述 (Mandatory / 必填)
A clear and concise description of what the bug is.
使用mindnlp调用bge-m3模型,部分报错
ERROR:root:An error occurred: The pointer[GetDevicePtr()] is null.
from mindspore import ops
from mindnlp.transformers import AutoModel, AutoTokenizer
from mindspore.ops._primitive_cache import _get_cache_prim
import mindspore as ms
print(ms.device_context.ascend.is_available)
ms.context.set_context(device_target="Ascend",device_id=1)
import time
import numpy as np
import logging
from enum import Enum
from fastapi import FastAPI, HTTPException, Query, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi_offline import FastAPIOffline
from pydantic import BaseModel
from typing import List, Optional
def normalize_numpy(dense_vecs, axis=-1):
"""
Normalize a numpy array along the specified axis using L2 normalization.
Parameters:
dense_vecs (numpy.ndarray): The input array to be normalized.
axis (int): The axis along which to compute the L2 norm. Default is -1.
Returns:
numpy.ndarray: The L2-normalized array.
"""
# norms = np.linalg.norm(dense_vecs, ord=2, axis=axis, keepdims=True)
return dense_vecs / np.linalg.norm(dense_vecs, ord=2, axis=axis, keepdims=True)
Please delete the backend not involved / 请删除不涉及的后端:
/device ascend/GPU/CPU/kirin/等其他芯片
Software Environment / 软件环境 (Mandatory / 必填):
-- MindSpore version (e.g., 1.7.0.Bxxx) :
-- Python version (e.g., Python 3.7.5) :
-- OS platform and distribution (e.g., Linux Ubuntu 16.04):
-- GCC/Compiler version (if compiled from source):
Describe the bug/ 问题描述 (Mandatory / 必填)
A clear and concise description of what the bug is.
使用mindnlp调用bge-m3模型,部分报错
ERROR:root:An error occurred: The pointer[GetDevicePtr()] is null.
This exception is caused by framework's unexpected error. Please create an issue at https://gitee.com/mindspore/mindspore/issues to get help.
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_device_address.cc:924 CopyDeviceToHost
from mindspore import ops
from mindnlp.transformers import AutoModel, AutoTokenizer
from mindspore.ops._primitive_cache import _get_cache_prim
import mindspore as ms
print(ms.device_context.ascend.is_available)
ms.context.set_context(device_target="Ascend",device_id=1)
import time
import numpy as np
import logging
from enum import Enum
from fastapi import FastAPI, HTTPException, Query, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi_offline import FastAPIOffline
from pydantic import BaseModel
from typing import List, Optional
logging.basicConfig(level=logging.ERROR)
app = FastAPIOffline()
app.add_middleware(
CORSMiddleware,
allow_origins=[""], # 允许的源列表,使用 [""] 可以允许所有源
allow_credentials=True, # 是否允许发送 Cookie
allow_methods=[""], # 允许的 HTTP 方法,如 ["GET", "POST"]
allow_headers=[""], # 允许的 HTTP 请求头
)
def normalize_numpy(dense_vecs, axis=-1):
"""
Normalize a numpy array along the specified axis using L2 normalization.
tokenizer = AutoTokenizer.from_pretrained('liuyanyi/bge-m3-hf',cache_dir="./cache")
embedding_model = AutoModel.from_pretrained('liuyanyi/bge-m3-hf',cache_dir="./cache")
tokenizer = AutoTokenizer.from_pretrained('/work/cache/model/liuyanyi/bge-m3-hf')
embedding_model = AutoModel.from_pretrained('/work/cache/model/liuyanyi/bge-m3-hf')
@app.post("/embeddings")
def encode_texts(
texts: Texts,
task: Task = Task.text_matching,
truncate_dim: Optional[TruncateDim] = Query(default=None),
max_str_length: Optional[int] = Query(default=None)
):
try:
input_ids = tokenizer(texts.texts[0], return_tensors="ms", padding=True, truncation=True)
output = embedding_model(**input_ids, return_dict=True)
dense_output = normalize_numpy(output.dense_output[0].asnumpy())
return {"code": 200,"embeddings": [dense_output.tolist()] }
except Exception as e:
logging.error(f"An error occurred: {e}")
return {"code": 500,"message": str(e)}
Ascend
/GPU
/CPU
) / 硬件环境:使用 swr.cn-central-221.ovaijisuan.com/mindformers/mindformers1.3_mindspore2.4:20241114镜像
Software Environment / 软件环境 (Mandatory / 必填):
-- MindSpore version (e.g., 1.7.0.Bxxx) :
-- Python version (e.g., Python 3.7.5) :
-- OS platform and distribution (e.g., Linux Ubuntu 16.04):
-- GCC/Compiler version (if compiled from source):
Excute Mode / 执行模式 (Mandatory / 必填)(
PyNative
/Graph
):To Reproduce / 重现步骤 (Mandatory / 必填)
Steps to reproduce the behavior:
Expected behavior / 预期结果 (Mandatory / 必填)
A clear and concise description of what you expected to happen.
Screenshots/ 日志 / 截图 (Mandatory / 必填)
If applicable, add screenshots to help explain your problem.
Additional context / 备注 (Optional / 选填)
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: