Browse Source

!54 remove env of run

From: @xu-yfei
Reviewed-by: 
Signed-off-by:
tags/v1.1.0
mindspore-ci-bot Gitee 5 years ago
parent
commit
07a5f4d80b
6 changed files with 191 additions and 21 deletions
  1. +10
    -3
      mindspore_serving/client/python/client.py
  2. +12
    -17
      mindspore_serving/example/add/export_model/add_model.py
  3. +1
    -0
      mindspore_serving/master/__init__.py
  4. +1
    -0
      mindspore_serving/worker/__init__.py
  5. +166
    -0
      mindspore_serving/worker/_check_version.py
  6. +1
    -1
      third_party/mindspore

+ 10
- 3
mindspore_serving/client/python/client.py View File

@@ -154,7 +154,8 @@ class Client:
method_name(str): The name of method supplied by servable.
version_number(int): The version number of servable, default 0,
0 meaning the maximum version number in all running versions.

max_msg_mb_size(int): The maximum acceptable gRPC message size in megabytes(MB), default 512,
value range [1, 512].
Raises:
RuntimeError: The type or value of the parameters is invalid, or other error happened.

@@ -169,12 +170,13 @@ class Client:
>>> result = client.infer(instances)
>>> print(result)
"""
def __init__(self, ip, port, servable_name, method_name, version_number=0):
def __init__(self, ip, port, servable_name, method_name, version_number=0, max_msg_mb_size=512):
_check_str("ip", ip)
_check_int("port", port, 0, 65535)
_check_str("servable_name", servable_name)
_check_str("method_name", method_name)
_check_int("version_number", version_number, 0)
_check_int("max_msg_mb_size", max_msg_mb_size, 1, 512)

self.ip = ip
self.port = port
@@ -183,7 +185,12 @@ class Client:
self.version_number = version_number

channel_str = str(ip) + ":" + str(port)
channel = grpc.insecure_channel(channel_str)
msg_bytes_size = max_msg_mb_size * 1024 * 1024
channel = grpc.insecure_channel(channel_str,
options=[
('grpc.max_send_message_length', msg_bytes_size),
('grpc.max_receive_message_length', msg_bytes_size),
])
self.stub = ms_service_pb2_grpc.MSServiceStub(channel)

def infer(self, instances):


+ 12
- 17
mindspore_serving/example/add/export_model/add_model.py View File

@@ -13,50 +13,45 @@
# limitations under the License.
# ============================================================================
"""add model generator"""

import os
from shutil import copyfile
import numpy as np

import mindspore.context as context
import mindspore.nn as nn
from mindspore.ops import operations as P
from mindspore import Tensor
from mindspore.train.serialization import export
import mindspore.ops as ops
import mindspore as ms

context.set_context(mode=context.GRAPH_MODE, device_target="Ascend")


class Net(nn.Cell):
"""Define Net of add"""
def __init__(self):
super(Net, self).__init__()
self.add = P.TensorAdd()
self.add = ops.TensorAdd()

def construct(self, x_, y_):
"""construct add net"""
return self.add(x_, y_)


def export_net():
"""Export add net of 2x2 + 2x2, and copy output model `tensor_add.mindir` to directory ../add/1"""
x = np.ones([2, 2]).astype(np.float32)
y = np.ones([2, 2]).astype(np.float32)
add = Net()
output = add(Tensor(x), Tensor(y))
export(add, Tensor(x), Tensor(y), file_name='tensor_add', file_format='MINDIR')
output = add(ms.Tensor(x), ms.Tensor(y))
ms.export(add, ms.Tensor(x), ms.Tensor(y), file_name='tensor_add', file_format='MINDIR')
dst_dir = '../add/1'
try:
os.mkdir(dst_dir)
except OSError:
pass
try:
dst_file = os.path.join(dst_dir, 'tensor_add.mindir')
if os.path.exists('tensor_add.mindir'):
copyfile('tensor_add.mindir', dst_file)
print("copy tensor_add.mindir to " + dst_dir + " success")
elif os.path.exists('tensor_add'):
copyfile('tensor_add', dst_file)
print("copy tensor_add to " + dst_dir + " success")
except:
print("copy tensor_add.mindir to " + dst_dir + " failed")

dst_file = os.path.join(dst_dir, 'tensor_add.mindir')
copyfile('tensor_add.mindir', dst_file)
print("copy tensor_add.mindir to " + dst_dir + " success")

print(x)
print(y)


+ 1
- 0
mindspore_serving/master/__init__.py View File

@@ -14,6 +14,7 @@
# ============================================================================
"""MindSpore Serving Master"""

from mindspore_serving.worker import _check_version
from ._master import start_grpc_server, start_restful_server, start_master_server, stop

__all__ = []


+ 1
- 0
mindspore_serving/worker/__init__.py View File

@@ -14,6 +14,7 @@
# ============================================================================
"""MindSpore Serving Worker."""

from . import _check_version
from . import register
from ._worker import start_servable, start_servable_in_master, stop



+ 166
- 0
mindspore_serving/worker/_check_version.py View File

@@ -0,0 +1,166 @@
# Copyright 2020 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""version and config check"""
import os
import sys
from pathlib import Path


class AscendEnvChecker:
"""ascend environment check"""

def __init__(self):
atlas_nnae_version = "/usr/local/Ascend/nnae/latest/fwkacllib/version.info"
atlas_toolkit_version = "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib/version.info"
hisi_fwk_version = "/usr/local/Ascend/fwkacllib/version.info"
hisi_atc_version = "/usr/local/Ascend/atc/version.info"
if os.path.exists(atlas_nnae_version):
# atlas default path
self.fwk_path = "/usr/local/Ascend/nnae/latest/fwkacllib"
self.op_impl_path = "/usr/local/Ascend/nnae/latest/opp/op_impl/built-in/ai_core/tbe"
self.tbe_path = self.fwk_path + "/lib64"
self.cce_path = self.fwk_path + "/ccec_compiler/bin"
self.fwk_version = atlas_nnae_version
self.op_path = "/usr/local/Ascend/nnae/latest/opp"
elif os.path.exists(atlas_toolkit_version):
# atlas default path
self.fwk_path = "/usr/local/Ascend/ascend-toolkit/latest/fwkacllib"
self.op_impl_path = "/usr/local/Ascend/ascend-toolkit/latest/opp/op_impl/built-in/ai_core/tbe"
self.tbe_path = self.fwk_path + "/lib64"
self.cce_path = self.fwk_path + "/ccec_compiler/bin"
self.fwk_version = atlas_toolkit_version
self.op_path = "/usr/local/Ascend/ascend-toolkit/latest/opp"
elif os.path.exists(hisi_fwk_version):
# hisi default path
self.fwk_path = "/usr/local/Ascend/fwkacllib"
self.op_impl_path = "/usr/local/Ascend/opp/op_impl/built-in/ai_core/tbe"
self.tbe_path = self.fwk_path + "/lib64"
self.cce_path = self.fwk_path + "/ccec_compiler/bin"
self.fwk_version = hisi_fwk_version
self.op_path = "/usr/local/Ascend/opp"
elif os.path.exists(hisi_atc_version):
# hisi 310 default path
self.fwk_path = "/usr/local/Ascend/atc"
self.op_impl_path = "/usr/local/Ascend/opp/op_impl/built-in/ai_core/tbe"
self.tbe_path = self.fwk_path + "/lib64"
self.cce_path = self.fwk_path + "/ccec_compiler/bin"
self.fwk_version = hisi_fwk_version
self.op_path = "/usr/local/Ascend/opp"
else:
# custom or unknown environment
self.fwk_path = ""
self.op_impl_path = ""
self.tbe_path = ""
self.cce_path = ""
self.fwk_version = ""
self.op_path = ""

# env
self.path = os.getenv("PATH")
self.python_path = os.getenv("PYTHONPATH")
self.ld_lib_path = os.getenv("LD_LIBRARY_PATH")
self.ascend_opp_path = os.getenv("ASCEND_OPP_PATH")

# check content
self.path_check = "/fwkacllib/ccec_compiler/bin"
self.python_path_check = "opp/op_impl/built-in/ai_core/tbe"
self.ld_lib_path_check_fwk = "/fwkacllib/lib64"
self.ld_lib_path_check_addons = "/add-ons"
self.ascend_opp_path_check = "/op"
self.v = ""

def check_env(self, e):
"""check system env"""
self._check_env()
raise e

def set_env(self):
"""set env: LD_LIBRARY_PATH, PATH, ASCEND_OPP_PATH"""
if not self.tbe_path:
self._check_env()
return

try:
# pylint: disable=unused-import
import te
except RuntimeError:
if Path(self.tbe_path).is_dir():
if os.getenv('LD_LIBRARY_PATH'):
os.environ['LD_LIBRARY_PATH'] = self.tbe_path + ":" + os.environ['LD_LIBRARY_PATH']
else:
os.environ['LD_LIBRARY_PATH'] = self.tbe_path
else:
raise EnvironmentError(
f"No such directory: {self.tbe_path}, Please check if Ascend 910 AI software package is "
"installed correctly.")

if Path(self.op_impl_path).is_dir():
sys.path.append(self.op_impl_path)
else:
raise EnvironmentError(
f"No such directory: {self.op_impl_path}, Please check if Ascend 910 AI software package is "
"installed correctly.")

if Path(self.cce_path).is_dir():
os.environ['PATH'] = self.cce_path + ":" + os.environ['PATH']
else:
raise EnvironmentError(
f"No such directory: {self.cce_path}, Please check if Ascend 910 AI software package is "
"installed correctly.")

if self.op_path is None:
pass
elif Path(self.op_path).is_dir():
os.environ['ASCEND_OPP_PATH'] = self.op_path
else:
raise EnvironmentError(
f"No such directory: {self.op_path}, Please check if Ascend 910 AI software package is "
"installed correctly.")

def _check_env(self):
"""ascend dependence path check"""
if self.path is None or self.path_check not in self.path:
print("Can not find ccec_compiler(need by mindspore-ascend), please check if you have set env "
"PATH, you can reference to the installation guidelines https://www.mindspore.cn/install")

if self.python_path is None or self.python_path_check not in self.python_path:
print(
"Can not find tbe op implement(need by mindspore-ascend), please check if you have set env "
"PYTHONPATH, you can reference to the installation guidelines "
"https://www.mindspore.cn/install")

if self.ld_lib_path is None or not (self.ld_lib_path_check_fwk in self.ld_lib_path and
self.ld_lib_path_check_addons in self.ld_lib_path):
print("Can not find driver so(need by mindspore-ascend), please check if you have set env "
"LD_LIBRARY_PATH, you can reference to the installation guidelines "
"https://www.mindspore.cn/install")

if self.ascend_opp_path is None or self.ascend_opp_path_check not in self.ascend_opp_path:
print(
"Can not find opp path (need by mindspore-ascend), please check if you have set env ASCEND_OPP_PATH, "
"you can reference to the installation guidelines https://www.mindspore.cn/install")


def check_version_and_env_config():
"""check version and env config"""
env_checker = AscendEnvChecker()

try:
env_checker.set_env()
except ImportError as e:
env_checker.check_env(e)


check_version_and_env_config()

+ 1
- 1
third_party/mindspore

@@ -1 +1 @@
Subproject commit 058fbd2d1f2fac3e5dd975114ec165c10c7e18e7
Subproject commit 3cc18c0f71a58699ac25d17c4a270122ad56b11f

Loading…
Cancel
Save