lanzhiwang commited on
Commit
c3f6e1f
1 Parent(s): 8fe72f7

download models

Browse files
Files changed (4) hide show
  1. app.py +14 -0
  2. deploy/knative-serving.yaml +76 -0
  3. deploy/nodeport.yaml +13 -0
  4. deploy/pvc.yaml +27 -0
app.py CHANGED
@@ -1,7 +1,21 @@
 
 
1
  import gradio as gr
2
  from transformers import pipeline
3
  from transformers import AutoTokenizer, AutoModelForCausalLM
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path="/root/.cache/huggingface/hub/models")
6
  model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path="/root/.cache/huggingface/hub/models")
7
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
 
1
+ import os
2
+ import subprocess
3
  import gradio as gr
4
  from transformers import pipeline
5
  from transformers import AutoTokenizer, AutoModelForCausalLM
6
 
7
+ # 下载模型
8
+ base_dir = "/root/.cache/huggingface/hub"
9
+ if not os.path.isdir(base_dir):
10
+ os.makedirs(base_dir)
11
+
12
+ cmd_list = ["cd", "base_dir", "&&", "git clone", "https://huggingface.co/gpt2", "models"]
13
+ cmd_str = "".join(cmd)
14
+ print("cmd_str:", cmd_str)
15
+ ret, out = subprocess.getstatusoutput(cmd_str)
16
+ print("ret:", ret)
17
+ print("out:", out)
18
+
19
  tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path="/root/.cache/huggingface/hub/models")
20
  model = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path="/root/.cache/huggingface/hub/models")
21
  generator = pipeline('text-generation', model=model, tokenizer=tokenizer)
deploy/knative-serving.yaml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: serving.knative.dev/v1
2
+ kind: Service
3
+ metadata:
4
+ name: custom-ksvc-gpt2
5
+ namespace: kubeflow-admin-cpaas-io
6
+ spec:
7
+ template:
8
+ metadata:
9
+ annotations:
10
+ # 表示自动扩缩容使用 kpa 类型,也是 Knative 默认类型
11
+ autoscaling.knative.dev/class: "kpa.autoscaling.knative.dev"
12
+ # 表示平均每个 pod 支持 10 个并发
13
+ autoscaling.knative.dev/target: "10"
14
+ # 表示 Knative service 最小 pods 数为 1
15
+ autoscaling.knative.dev/minScale: "1"
16
+ # 最大 pods 数为 5
17
+ autoscaling.knative.dev/maxScale: "5"
18
+ spec:
19
+ containerConcurrency: 1
20
+ initContainers:
21
+ - args:
22
+ # 这里指定用户 space repo 的地址
23
+ # https://huggingface.co/gpt2
24
+ # https://huggingface.co/spaces/lanzhiwang/first-gradio
25
+ # https://gitee.com/lanzhiwang/first-gradio.git
26
+ - git+lfs://gitee.com/lanzhiwang/first-gradio
27
+ - /mnt/app
28
+ # 这个是固定的镜像,用于拉取用户 space 代码
29
+ image: 10.0.200.210:11443/mlops/storage-initializer:v0.8.0-acp-0914
30
+ imagePullPolicy: IfNotPresent
31
+ name: storage-initializer
32
+ # env:
33
+ # - name: HTTPS_PROXY
34
+ # value: http://192.168.144.12:7890
35
+ resources:
36
+ limits:
37
+ cpu: "1"
38
+ memory: 2Gi
39
+ requests:
40
+ cpu: 100m
41
+ memory: 100Mi
42
+ volumeMounts:
43
+ - mountPath: /mnt/app
44
+ name: space-code-location
45
+ containers:
46
+ - env:
47
+ - name: SPACE_DIR
48
+ value: /mnt/app
49
+ - name: APP_NAME
50
+ value: first-gradio
51
+ - name: PIP_MIRROR
52
+ value: https://pypi.tuna.tsinghua.edu.cn/simple
53
+ - name: APP_FILE
54
+ value: app.py
55
+ # 镜像确定方式参考上文
56
+ image: dev.local/gradio-runtime:v3.4
57
+ command:
58
+ - bash
59
+ - /home/user/app/endpoint.sh
60
+ imagePullPolicy: IfNotPresent
61
+ ports:
62
+ - containerPort: 7860
63
+ name: space-container
64
+ volumeMounts:
65
+ - mountPath: /root/.cache/huggingface/hub
66
+ name: models-location
67
+ - mountPath: /mnt/app
68
+ name: space-code-location
69
+ timeoutSeconds: 600
70
+ volumes:
71
+ - name: space-code-location
72
+ persistentVolumeClaim:
73
+ claimName: custom-ksvc-gpt2-app
74
+ - name: models-location
75
+ persistentVolumeClaim:
76
+ claimName: custom-ksvc-gpt2-models
deploy/nodeport.yaml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: v1
2
+ kind: Service
3
+ metadata:
4
+ name: custom-ksvc-gpt2-nodeport
5
+ namespace: kubeflow-admin-cpaas-io
6
+ spec:
7
+ ports:
8
+ - port: 7860
9
+ targetPort: 7860
10
+ protocol: TCP
11
+ selector:
12
+ serving.knative.dev/revisionUID: 8037843b-8ffa-4686-a33f-36134dfaafb7
13
+ type: NodePort
deploy/pvc.yaml ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ apiVersion: v1
2
+ kind: PersistentVolumeClaim
3
+ metadata:
4
+ name: custom-ksvc-gpt2-app
5
+ namespace: kubeflow-admin-cpaas-io
6
+ spec:
7
+ accessModes:
8
+ - ReadWriteOnce
9
+ resources:
10
+ requests:
11
+ storage: 2Gi
12
+ storageClassName: sc-topolvm
13
+ volumeMode: Filesystem
14
+ ---
15
+ apiVersion: v1
16
+ kind: PersistentVolumeClaim
17
+ metadata:
18
+ name: custom-ksvc-gpt2-models
19
+ namespace: kubeflow-admin-cpaas-io
20
+ spec:
21
+ accessModes:
22
+ - ReadWriteOnce
23
+ resources:
24
+ requests:
25
+ storage: 10Gi
26
+ storageClassName: sc-topolvm
27
+ volumeMode: Filesystem