Skip to content

Commit

Permalink
修复部分显示bug
Browse files Browse the repository at this point in the history
  • Loading branch information
data-infra committed Jun 11, 2024
1 parent 76777a2 commit 6cd3435
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 72 deletions.
19 changes: 12 additions & 7 deletions myapp/models/model_dimension.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,21 @@ def table_html(self):
users = [user.strip() for user in users if user.strip()]
url_path = conf.get('MODEL_URLS',{}).get("dimension")
if g.user.is_admin() or g.user.username in users or '*' in self.owner:
return Markup(f'<a target=_blank href="{url_path}?targetId={self.id}">{self.table_name}</a>')
else:
return self.table_name
if self.sqllchemy_uri:
return Markup(f'<a target=_blank href="{url_path}?targetId={self.id}">{self.table_name}</a>')

return self.table_name

@property
def operate_html(self):
url=f'''
<a target=_blank href="/dimension_table_modelview/api/create_external_table/%s">{__("更新远程表")}</a> | <a target=_blank href="/dimension_table_modelview/api/external/%s">{__("建外表示例")}</a>
'''%(self.id,self.id)
return Markup(url)
if self.sqllchemy_uri:
url=f'''
<a target=_blank href="/dimension_table_modelview/api/create_external_table/%s">{__("更新远程表")}</a> | <a target=_blank href="/dimension_table_modelview/api/external/%s">{__("建外表示例")}</a>
'''%(self.id,self.id)
return Markup(url)
else:
return __("更新远程表")+" | "+__("建外表示例")




Expand Down
2 changes: 1 addition & 1 deletion myapp/models/model_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class Task(Model,ImportMixin,AuditMixinNullable,MyappModelBase):
job_template = relationship(
"Job_Template", foreign_keys=[job_template_id]
)
pipeline_id = Column(Integer, ForeignKey('pipeline.id'),comment='项目组id')
pipeline_id = Column(Integer, ForeignKey('pipeline.id'),comment='任务流id')
pipeline = relationship(
"Pipeline", foreign_keys=[pipeline_id]
)
Expand Down
9 changes: 0 additions & 9 deletions myapp/models/model_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,6 @@ def name_url(self):

if self.ide_type=='theia':
url = "/notebook/"+self.namespace + "/" + self.name+"/" + "#"+self.mount
elif self.ide_type=='matlab':
url = "/notebook/"+self.namespace + "/" + self.name+"/index.html"
elif self.ide_type=='rstudio' and not SERVICE_EXTERNAL_IP:
url1 = host+"/notebook/" + self.namespace + "/" + self.name + "/auth-sign-in?appUri=%2F"
url2 = host+"/notebook/" + self.namespace + "/" + self.name+"/"
a_html='''<a onclick="(function (){window.open('%s','_blank');window.open('%s','_blank')})()">%s</a>'''%(url1,url2,self.name)
return Markup(a_html)

# url = "/notebook/" + self.namespace + "/" + self.name+"/"
else:
if root:
url = '/notebook/jupyter/%s/lab/tree/%s' % (self.name,root.lstrip('/'))
Expand Down
7 changes: 6 additions & 1 deletion myapp/models/model_train_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ def project_url(self):

@property
def deploy(self):
ops=f'''
download_url = ''
if self.path or self.download_url:
download_url = f'<a href="/training_model_modelview/api/download/{self.id}">{__("下载")}</a> |'
else:
download_url = f'{__("下载")} |'
ops=download_url+f'''
<a href="/training_model_modelview/api/deploy/{self.id}">{__("发布")}</a>
'''
return Markup(ops)
Expand Down
7 changes: 0 additions & 7 deletions myapp/tools/start.sh

This file was deleted.

9 changes: 5 additions & 4 deletions myapp/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,21 +1533,22 @@ def check_max_gpu(gpu_num, src_gpu_num=0):
return gpu_num

gpu_num, gpu_type, resource_name = get_gpu(resource_gpu)
src_gpu_num,_,_ = get_gpu(src_resource_gpu) if src_resource_gpu else 0,0,0
src_gpu_num = 0
if src_resource_gpu:
src_gpu_num, _, _ = get_gpu(src_resource_gpu)

if hasattr(g,'user') and not g.user.is_admin():
if hasattr(g,'user') and not g.user.is_admin():
resource_gpu = check_max_gpu(gpu_num, src_gpu_num)
if math.ceil(float(resource_gpu))==resource_gpu:
resource_gpu = math.ceil(float(resource_gpu))
if gpu_type:
resource_gpu +=f'({gpu_type})'
resource_gpu = str(resource_gpu)+f'({gpu_type})'
else:
resource_gpu = resource_gpu

return str(resource_gpu)



def check_resource(resource_memory,resource_cpu,resource_gpu,src_resource_memory=None,src_resource_cpu=None,src_resource_gpu=None):
new_resource_memory = check_resource_memory(resource_memory,src_resource_memory)
new_resource_memory = str(math.ceil(float(str(new_resource_memory).replace('G',''))))+"G"
Expand Down
52 changes: 43 additions & 9 deletions myapp/utils/py/py_k8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,21 @@ def get_pods(self, namespace=None, service_name=None, pod_name=None, labels={},s
pod_name_temp = address.target_ref.name
pod = self.v1.read_namespaced_pod(name=pod_name_temp, namespace=namespace)
all_pods.append(pod)
elif (namespace and status and status.lower()=='running'):
all_endpoints = self.v1.list_namespaced_endpoints(namespace=namespace) # 先查询入口点,
subsets = all_endpoints.subsets
addresses = subsets[0].addresses # 只取第一个子网
for address in addresses:
pod_name_temp = address.target_ref.name
pod = self.v1.read_namespaced_pod(name=pod_name_temp, namespace=namespace)
all_pods.append(pod)
elif (namespace and status):
if status.lower()=='running':
all_endpoints = self.v1.list_namespaced_endpoints(namespace=namespace) # 先查询入口点,
subsets = all_endpoints.subsets
addresses = subsets[0].addresses # 只取第一个子网
for address in addresses:
pod_name_temp = address.target_ref.name
pod = self.v1.read_namespaced_pod(name=pod_name_temp, namespace=namespace)
all_pods.append(pod)
else:
src_pods = self.v1.list_namespaced_pod(namespace).items
for pod in src_pods:
if pod.status and pod.status.phase == status:
all_pods.append(pod)


elif (namespace and labels):
src_pods = self.v1.list_namespaced_pod(namespace).items
Expand Down Expand Up @@ -1068,9 +1075,27 @@ def make_pod(self, namespace, name, labels, command, args, volume_mount, working
# 设置卡型
if gpu_type and gpu_type.strip():
nodeSelector['gpu-type'] = gpu_type
# 独占模式,尽量聚集在一个,避免卡零碎
if gpu_num >= 1:
nodeSelector['gpu'] = 'true'

labels['gpu']='true'
# 优先选择gpu卡占用的地方,这样不容易造成卡的零碎化占用
affinity = client.V1Affinity(
node_affinity=None,
pod_anti_affinity=None,
pod_affinity=client.V1PodAffinity(
preferred_during_scheduling_ignored_during_execution=[
client.V1WeightedPodAffinityTerm(
pod_affinity_term=client.V1PodAffinityTerm(
topology_key="kubernetes.io/hostname",
label_selector = client.V1LabelSelector(
match_labels={
"gpu": 'true'
}
)
),
weight=10)])
)
k8s_volumes, k8s_volume_mounts = self.get_volume_mounts(volume_mount, username)

containers = [self.make_container(name=name,
Expand Down Expand Up @@ -1290,6 +1315,15 @@ def delete_deployment(self, namespace, name=None, labels=None):
except Exception as e:
print(e)

# deploymnet伸缩容
def scale_deployment(self,namespace, name, replicas):
try:
deployment = self.AppsV1Api.read_namespaced_deployment(name=name, namespace=namespace)
deployment.spec.replicas = int(replicas)
self.AppsV1Api.replace_namespaced_deployment(name=name, namespace=namespace, body=deployment)
except Exception as e:
print(e)

# @pysnooper.snoop()
def create_deployment(self, namespace, name, replicas, labels, command, args, volume_mount,working_dir,
node_selector, resource_memory, resource_cpu, resource_gpu, image_pull_policy,
Expand Down
2 changes: 1 addition & 1 deletion myapp/utils/sqllab/base_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def submit_task(self, qid, enable_async=True):
async_task = handle_task.delay(qid, username=g.user.username)
else:
stage, status, _err_msg = handle_task(qid, username=g.user.username)
if _err_msg != "":
if _err_msg:
raise RuntimeError(_err_msg)

res = self.get_result(qid)
Expand Down
2 changes: 2 additions & 0 deletions myapp/views/baseApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1849,6 +1849,8 @@ def make_ui_info(self, ret_src):

local_validators.append(val)
ret['validators'] = local_validators
# 去除重复
ret['validators'] = [json.loads(x) for x in list(set([json.dumps(x) for x in ret['validators']]))]

# 统一规范前端type和选择时value
# 选择器
Expand Down
2 changes: 1 addition & 1 deletion myapp/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def menu(self):
"children": [
{
"name": 'chat',
"title": __('知识库'),
"title": __('智能体'),
"icon": '<svg t="1682394317506" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2833" width="50" height="50"><path d="M431.207059 2.199998C335.414129 13.19899 257.420186 72.593947 219.024215 163.78688l-6.199996 14.797989-19.997985 5.799996C104.233299 210.582846 38.840347 279.776795 15.041364 372.369727c-6.999995 27.39698-8.999993 71.393948-4.199997 99.990927 7.399995 44.996967 26.597981 88.592935 53.795961 121.989911l9.198993 11.399991-5.199996 19.597986c-6.799995 26.597981-8.598994 74.593945-3.799997 103.190924 14.799989 87.392936 75.193945 163.58688 155.587886 196.383857 46.395966 18.998986 95.99193 24.797982 142.187895 16.798987l11.599992-1.999998 18.597986 17.598987c30.396978 28.596979 66.593951 48.395965 108.789921 59.994956 25.998981 6.999995 83.193939 8.999993 111.391918 3.599997 53.194961-9.799993 98.391928-33.797975 137.1889-72.794946 27.996979-28.196979 51.194963-64.393953 59.794956-93.591932 2.199998-6.999995 3.599997-8.599994 8.798993-9.799993 12.798991-2.598998 42.595969-13.39799 56.194959-20.196985 35.996974-17.998987 72.793947-49.195964 94.792931-80.593941 19.797985-28.197979 36.196973-65.993952 44.395967-102.990924 1.799999-7.799994 2.799998-24.997982 2.799998-48.995965 0-33.997975-0.6-38.796972-5.799996-58.995956-9.998993-38.795972-25.997981-71.993947-48.395964-100.190927l-10.198993-12.799991 4.399997-17.597987c26.79698-102.790925-16.798988-217.181841-105.391923-276.576797-30.996977-20.598985-58.194957-31.997977-95.59193-40.196971-22.397984-4.999996-70.993948-5.799996-91.991932-1.799998-12.399991 2.399998-12.99999 2.399998-15.799989-1.599999-4.598997-7.199995-34.795975-31.596977-52.794961-42.995969C548.196973 9.598993 486.603019-4.199997 431.207059 2.199998z m45.395967 67.793951c25.197982 2.399998 40.39697 6.399995 61.394955 16.198988 16.797988 7.799994 41.995969 23.397983 41.995969 25.997981 0 0.799999-45.595967 27.79798-101.390926 59.794956-55.995959 32.196976-104.591923 60.794955-108.19092 63.394954-14.799989 10.998992-14.399989 8.399994-14.59999 97.591928-0.2 43.995968-0.999999 110.389919-1.599998 147.387892l-1.199 67.393951-42.596968-24.397982-42.595969-24.397982 0.599999-134.988902c0.799999-154.386887 0.2-147.987892 19.597986-187.383862 29.797978-60.395956 86.792936-100.191927 151.987889-106.591922 8.199994-0.799999 15.398989-1.599999 15.998988-1.599999 0.6-0.2 9.798993 0.6 20.597985 1.599999z m268.977803 82.992939c73.393946 15.399989 132.189903 74.193946 147.387892 147.987892 3.599997 16.998988 4.599997 62.394954 1.599999 67.79495-1.199999 2.399998-22.797983-9.399993-108.590921-59.394957-105.391923-61.394955-107.191921-62.394954-117.989913-62.394954-10.799992 0-13.19999 1.399999-137.989899 73.593946l-126.989907 73.393946-0.599-49.395963c-0.2-27.19798 0.2-49.995963 1-50.795963 3.799997-3.599997 209.182847-121.189911 223.581836-127.989906 35.796974-16.797988 77.992943-21.397984 118.589913-12.798991z m-537.955606 362.369735c3.199998 4.599997 37.596972 25.398981 130.389904 78.993942 69.393949 39.796971 125.988908 72.993947 125.988908 73.593946 0 0.6-5.599996 4.199997-12.598991 8.199994-6.799995 3.799997-25.997981 14.797989-42.596968 24.397982l-30.196978 17.597987-107.790921-62.194954c-59.194957-34.196975-114.589916-67.393951-122.78991-73.793946-29.397978-22.597983-56.395959-63.793953-66.194952-101.190926-6.199995-24.197982-7.199995-60.794955-2.199998-84.992938 7.599994-36.996973 23.397983-66.994951 49.195964-93.792931 17.398987-17.997987 33.197976-29.396978 55.195959-40.195971l16.997988-8.199994 0.999999 127.589907 0.999999 127.589906 4.599997 6.398996zM750.379825 367.169731c56.394959 32.596976 108.389921 62.994954 115.589916 67.593951 43.396968 28.597979 73.593946 75.793944 81.99294 127.989906 3.599997 21.597984 1.599999 61.994955-3.999997 80.992941-8.998993 31.397977-24.996982 58.995957-47.594966 82.593939-17.598987 18.397987-48.195965 38.995971-65.794951 44.395967l-4.599997 1.399999v-124.189909c0-138.188899 0.4-133.389902-13.59899-143.387895-4.399997-2.999998-62.393954-37.196973-128.988906-75.593944-66.594951-38.596972-121.189911-70.393948-121.189911-70.993948-0.2-0.799999 83.592939-49.795964 85.192938-49.995964 0.4 0 46.595966 26.597981 102.991924 59.194957z m-181.385867 50.195963l54.99596 31.596977v127.989906l-55.19596 31.596977-55.194959 31.797977-39.196971-22.598983c-21.797984-12.398991-46.795966-26.99698-55.994959-32.196977l-16.398988-9.799993 0.399999-63.393953 0.6-63.394954 53.99496-31.396977c29.797978-17.198987 54.79596-31.397977 55.59596-31.397977 0.799999-0.2 26.197981 13.99999 56.394958 31.197977z m147.587892 85.592938l41.39697 23.797982v127.389907c0 139.787898-0.4 146.187893-11.999991 178.384869-11.597992 31.796977-36.595973 65.394952-64.593953 86.592937-6.799995 5.199996-21.397984 13.79899-32.396976 18.997986-51.995962 24.997982-109.59092 25.597981-162.586881 1.799999-12.598991-5.799996-40.39697-23.397983-40.396971-25.797982 0-0.6 46.996966-28.196979 104.191924-61.194955 57.394958-32.996976 107.190921-62.794954 110.789919-66.193951 3.799997-3.799997 7.399995-9.999993 8.799993-15.399989 1.599999-6.398995 2.199998-50.994963 2.199999-151.386889 0-78.392943 0.799999-141.987896 1.599999-141.587896 0.799999 0.2 20.197985 11.398992 42.995968 24.597982zM622.590919 732.139464c-3.799997 3.599997-205.38285 119.189913-221.781838 126.989907-26.597981 12.798991-47.995965 17.397987-79.792941 17.397987-19.798985 0-30.197978-0.999999-43.596968-4.199997-68.59395-16.997988-120.589912-66.193952-140.587897-133.787902-5.599996-18.798986-8.599994-57.395958-5.999996-75.193945l1.399999-9.199993 50.395963 29.197979c174.185872 100.391926 165.185879 95.59193 176.185871 95.591929 9.598993-0.2 16.597988-3.799997 137.1879-73.393946l126.989907-73.393946 0.599999 49.395964c0.2 26.99798-0.2 49.795964-0.999999 50.595963z" p-id="2834"></path></svg>',
"menu_type": "api",
"url": '/chat_modelview/api/',
Expand Down
4 changes: 2 additions & 2 deletions myapp/views/view_inferenceserving.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class InferenceService_ModelView_base():
"model_status": {"type": "ellip2", "width": 100},
"modified": {"type": "ellip2", "width": 150},
"operate_html": {"type": "ellip2", "width": 350},
"resource": {"type": "ellip2", "width": 300},
"resource": {"type": "ellip2", "width": 350},
}
search_columns = ['name', 'created_by', 'project', 'service_type', 'label', 'model_name', 'model_version',
'model_path', 'host', 'model_status', 'resource_gpu']
Expand Down Expand Up @@ -187,7 +187,7 @@ class InferenceService_ModelView_base():
),
"hpa": StringField(
_('弹性伸缩'),
default='cpu:50%,gpu:50%',
default='',
description= _('弹性伸缩容的触发条件:可以使用cpu/mem/gpu/qps等信息,可以使用其中一个指标或者多个指标,示例:cpu:50%,mem:50%,gpu:50%'),
widget=BS3TextFieldWidget()
),
Expand Down
5 changes: 2 additions & 3 deletions myapp/views/view_nni.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,7 @@ def make_nnijob(self,k8s_client,namespace,nni):
"name": nni.name,
"namespace": namespace,
"labels": {
"type": "nni",
"component": "nni",
"pod-type": "nni",
"role": "master",
"app": nni.name,
"username": nni.created_by.username
Expand Down Expand Up @@ -725,7 +724,7 @@ class NNI_ModelView_Api(NNI_ModelView_Base, MyappModelRestApi):
'parallel_trial_count', 'max_trial_count', 'objective_type',
'objective_goal', 'objective_metric_name', 'algorithm_name',
'algorithm_setting', 'parameters', 'job_json', 'working_dir', 'node_selector',
'resource_memory', 'resource_cpu', 'alert_status', 'job_worker_image', 'job_worker_command']
'resource_memory', 'resource_cpu','resource_gpu', 'alert_status', 'job_worker_image', 'job_worker_command']
edit_columns = add_columns


Expand Down
2 changes: 1 addition & 1 deletion myapp/views/view_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Notebook_ModelView_Base():
"resource": {"type": "ellip2", "width": 300},
"status": {"type": "ellip2", "width": 100},
"renew": {"type": "ellip2", "width": 200},
"save": {"type": "ellip2", "width": 200}
"save": {"type": "ellip2", "width": 100}
}
add_form_query_rel_fields = {
"project": [["name", Project_Join_Filter, 'org']]
Expand Down
Loading

0 comments on commit 6cd3435

Please sign in to comment.