Compare commits

...

11 Commits

Author SHA1 Message Date
9718a368c3 update normalize method 2024-07-04 16:38:17 +08:00
729ea183d1 备份部署配置 2024-06-05 09:55:53 +08:00
7a154754db fix: typo 2024-06-04 18:02:58 +08:00
41c1205dfb fix: cpu模式不支持 float16 2024-06-04 17:57:15 +08:00
947cc86ad8 typo 2024-06-04 17:56:55 +08:00
88f1bb8b64 Revert "lfs change to acge_text_embedding"
This reverts commit 2bf403dca7.
2024-06-04 14:06:40 +08:00
c4d65ebcfd add .gitlab-ci.yaml 2024-06-04 14:05:23 +08:00
2bf403dca7 lfs change to acge_text_embedding 2024-06-04 12:29:59 +08:00
4201ad34ff lfs add acge-large-text 2024-06-04 12:29:22 +08:00
dea0ba42ff lfs track models/** 2024-06-04 12:28:22 +08:00
673d7b05e2 add .dockerignore 2024-06-04 11:53:37 +08:00
11 changed files with 124 additions and 12 deletions

View File

@@ -1,2 +1,3 @@
__pycache__
/venv
/venv
/huggingface

1
.gitattributes vendored Normal file
View File

@@ -0,0 +1 @@
models/** filter=lfs diff=lfs merge=lfs -text

36
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,36 @@
# To contribute improvements to CI/CD templates, please follow the Development guide at:
# https://docs.gitlab.com/ee/development/cicd/templates.html
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Docker.gitlab-ci.yml
# Build a Docker image with CI/CD and push to the GitLab registry.
# Docker-in-Docker documentation: https://docs.gitlab.com/ee/ci/docker/using_docker_build.html
#
# This template uses one generic job with conditional builds
# for the default branch and all other (MR) branches.
deploy:
# Use the official docker image.
image: docker:cli
stage: deploy
services:
- docker:dind
variables:
CI_REGISTRY: registry.waykey.net:7999
CI_REGISTRY_IMAGE: $CI_REGISTRY/spiderman/datamining/local-embedding-api
DOCKER_IMAGE_NAME: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
before_script:
- chmod 600 $CI_SSH_PRIVATE_KEY
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build --pull -t "$DOCKER_IMAGE_NAME" .
- docker push "$DOCKER_IMAGE_NAME"
- |
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
docker tag "$DOCKER_IMAGE_NAME" "$CI_REGISTRY_IMAGE:latest"
docker push "$CI_REGISTRY_IMAGE:latest"
fi
rules:
- if: $CI_COMMIT_BRANCH
exists:
- Dockerfile

View File

@@ -10,6 +10,4 @@ RUN pip install -r requirements_version.txt --no-cache-dir -i https://pypi.tuna.
COPY . .
RUN python acge_embedding.py
CMD ["python", "main.py"]

View File

@@ -1,17 +1,18 @@
from transformers import AutoModel, AutoTokenizer
from sklearn.preprocessing import normalize
import torch
import torch.nn.functional as F
device = "cuda" if torch.cuda.is_available() else "cpu"
print("Using device:", device)
model_name = "aspire/acge-large-zh"
model_name = "models/aspire--acge-large-zh"
print("Loading model", model_name)
model = (
AutoModel.from_pretrained(model_name, torch_dtype=torch.float16).eval().to(device)
AutoModel.from_pretrained(model_name, local_files_only=True).eval().to(device)
)
tokenizer = AutoTokenizer.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name, local_files_only=True)
print("Model", model_name, "loaded!")
@@ -43,9 +44,7 @@ def acge_embedding(text: list[str]) -> list[list[float]]:
~attention_mask[..., None].bool(), 0.0
)
vector = last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
vector = normalize(
vector.cpu().detach().numpy(),
norm="l2",
axis=1,
)
return vector.tolist()
# Normalize the output vectors
normalized_vector = F.normalize(vector, p=2, dim=1)
return normalized_vector.tolist()

62
local-embedding-api.yaml Normal file
View File

@@ -0,0 +1,62 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: local-embedding-api
labels:
app: local-embedding-api
spec:
replicas: 2
selector:
matchLabels:
app: local-embedding-api
template:
metadata:
labels:
app: local-embedding-api
spec:
imagePullSecrets:
- name: spiderman-regcred
containers:
- name: local-embedding-api
image: registry.waykey.net:7999/spiderman/datamining/local-embedding-api:latest
imagePullPolicy: Always
ports:
- containerPort: 7999
resources:
requests:
memory: "2000M"
limits:
memory: "4000M"
---
apiVersion: v1
kind: Service
metadata:
labels:
app: local-embedding-api
name: local-embedding-api
namespace: default
spec:
ports:
- port: 7999
protocol: TCP
targetPort: 7999
selector:
app: local-embedding-api
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: local-embedding-api
spec:
ingressClassName: nginx
rules:
- host: local-embedding-api.k8s.local
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: local-embedding-api
port:
number: 7999

BIN
models/aspire--acge-large-zh/config.json (Stored with Git LFS) Normal file

Binary file not shown.

BIN
models/aspire--acge-large-zh/pytorch_model.bin (Stored with Git LFS) Normal file

Binary file not shown.

BIN
models/aspire--acge-large-zh/special_tokens_map.json (Stored with Git LFS) Normal file

Binary file not shown.

BIN
models/aspire--acge-large-zh/tokenizer_config.json (Stored with Git LFS) Normal file

Binary file not shown.

BIN
models/aspire--acge-large-zh/vocab.txt (Stored with Git LFS) Normal file

Binary file not shown.