Skip to content

Commit

Permalink
Minor fix for running "mlflow deployments create -t triton --flavor t…
Browse files Browse the repository at this point in the history
…riton ..." (#5658)

UnboundLocalError: local variable 'meta_dict' referenced before assignment

The above error shows in listing models in Triton model repository
  • Loading branch information
yeahdongcn authored May 16, 2023
1 parent 96226c9 commit c7254d3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions deploy/mlflow-triton-plugin/mlflow_triton/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ def list_deployments(self):
)['Body'].read().decode('utf-8'))
elif os.path.isfile(mlflow_meta_path):
meta_dict = self._get_mlflow_meta_dict(d['name'])
else:
continue

d['triton_model_path'] = meta_dict['triton_model_path']
d['mlflow_model_uri'] = meta_dict['mlflow_model_uri']
Expand Down Expand Up @@ -288,7 +290,7 @@ def _generate_mlflow_meta_file(self, name, flavor, model_uri):
def _get_mlflow_meta_dict(self, name):
mlflow_meta_path = os.path.join(self.triton_model_repo, name,
_MLFLOW_META_FILENAME)

if 's3' in self.server_config:
mlflow_meta_dict = ast.literal_eval(self.server_config['s3'].get_object(
Bucket=self.server_config['s3_bucket'],
Expand Down Expand Up @@ -359,10 +361,10 @@ def _get_copy_paths(self, artifact_path, name, flavor):
return copy_paths

def _walk(self, path):
"""Walk a path like os.walk() if path is dir,
"""Walk a path like os.walk() if path is dir,
return file in the expected format otherwise.
:param path: dir or file path
:return: root, dirs, files
"""
if os.path.isfile(path):
Expand All @@ -375,16 +377,16 @@ def _walk(self, path):
def _copy_files_to_triton_repo(self, artifact_path, name, flavor):
copy_paths = self._get_copy_paths(artifact_path, name, flavor)
for key in copy_paths:
if 's3' in self.server_config:
if 's3' in self.server_config:
# copy model dir to s3 recursively
for root, dirs, files in self._walk(copy_paths[key]['from']):
for filename in files:
local_path = os.path.join(root, filename)

if flavor == "onnx":
s3_path = os.path.join(
copy_paths[key]['to'].replace(
self.server_config['triton_model_repo'], ''),
self.server_config['triton_model_repo'], ''),
filename,
).replace('/', '', 1)

Expand All @@ -394,9 +396,9 @@ def _copy_files_to_triton_repo(self, artifact_path, name, flavor):
copy_paths[key]['from'],
)
s3_path = f'{name}/{rel_path}'

self.server_config['s3'].upload_file(
local_path,
local_path,
self.server_config['s3_bucket'],
s3_path,
)
Expand All @@ -410,13 +412,13 @@ def _copy_files_to_triton_repo(self, artifact_path, name, flavor):
os.makedirs(copy_paths[key]['to'])
shutil.copy(copy_paths[key]['from'], copy_paths[key]['to'])

if 's3' not in self.server_config:
if 's3' not in self.server_config:
triton_deployment_dir = os.path.join(self.triton_model_repo, name)
version_folder = os.path.join(triton_deployment_dir, "1")
os.makedirs(version_folder, exist_ok=True)

return copy_paths

def _delete_mlflow_meta(self, filepath):
if 's3' in self.server_config:
self.server_config['s3'].delete_object(
Expand All @@ -433,20 +435,20 @@ def _delete_deployment_files(self, name):

if 's3' in self.server_config:
objs = self.server_config['s3'].list_objects(
Bucket=self.server_config['s3_bucket'],
Bucket=self.server_config['s3_bucket'],
Prefix=name,
)

for key in objs['Contents']:
key = key['Key']
try:
self.server_config['s3'].delete_object(
Bucket=self.server_config['s3_bucket'],
Key=key,
)
)
except Exception as e:
raise Exception(f'Could not delete {key}: {e}')

else:
# Check if the deployment directory exists
if not os.path.isdir(triton_deployment_dir):
Expand Down

0 comments on commit c7254d3

Please sign in to comment.