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

使用 BAAI/bge-reranker-v2-minicpm-layerwise 程序会重启 #107

Open
itchangc opened this issue Nov 17, 2024 · 1 comment
Open

使用 BAAI/bge-reranker-v2-minicpm-layerwise 程序会重启 #107

itchangc opened this issue Nov 17, 2024 · 1 comment

Comments

@itchangc
Copy link
Contributor

///


/// 模型写死
///

public static dynamic LoadModel(string pythondllPath, string modelName)
{
lock (lockobj)
{
if (model == null)
{
PyRunTime.InitRunTime(pythondllPath);
try
{
using (GIL())// 初始化Python环境的Global Interpreter Lock)
{
dynamic modelscope = Py.Import("modelscope");
dynamic flagEmbedding = Py.Import("FlagEmbedding");
dynamic model_dir = modelscope.snapshot_download(modelName, revision: "master");

                if (modelName == "BAAI/bge-reranker-v2-minicpm-layerwise")
                {
                    dynamic flagReranker = flagEmbedding.LayerWiseFlagLLMReranker(model_dir, use_fp16: true);
                    model = flagReranker;
                }
                else
                {
                    dynamic flagReranker = flagEmbedding.FlagReranker(model_dir, use_fp16: true);
                    model = flagReranker;
                }
                return model;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    else
    {
        return model;
    }
}

}

下面是调用数据:
PyList cutoffLayers = new PyList();
cutoffLayers.Append(new PyInt(8));
dynamic scores = model.compute_score(pyList, cutoff_layers: cutoffLayers);

执行 model.compute_score 就重启。
image

@xuzeyu91
Copy link
Collaborator

看报错信息是端口被占用

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants