Skip to content

Mlc #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 34 commits into from
Closed

Mlc #125

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f5225bd
Update test-mlperf-inference-resnet50.yml
arjunsuresh Jan 10, 2025
1509b4e
Merge branch 'mlcommons:dev' into dev
arjunsuresh Jan 10, 2025
934dab4
Update test-cm-based-submission-generation.yml
arjunsuresh Jan 10, 2025
52fd2e6
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
4ed39a7
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
efc7263
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
e2de041
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
ec30f8e
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
1ce00d1
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
cffb9e7
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
1ccc9ff
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
3c6147f
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
4d7bf3e
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
ce4aa28
[Automated Commit] Format Codebase
arjunsuresh Jan 10, 2025
e43e36c
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
69c8943
Merge branch 'dev' into dev
arjunsuresh Jan 10, 2025
28e4946
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
7fd1715
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
a4ece9a
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
989b18f
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
dc1fef7
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
6b53dbf
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
fbe52d8
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
87bcbaa
[Automated Commit] Format Codebase
arjunsuresh Jan 11, 2025
045f38f
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
45c3181
Merge branch 'dev' into dev
arjunsuresh Jan 11, 2025
1467c28
Added a common automation base class in MLC
arjunsuresh Jan 13, 2025
05f1ae8
[Automated Commit] Format Codebase
arjunsuresh Jan 13, 2025
0e6a4f9
Changes for mlc
arjunsuresh Jan 15, 2025
bdcabe1
[Automated Commit] Format Codebase
arjunsuresh Jan 15, 2025
90af1f8
Script automation meta added
arjunsuresh Jan 15, 2025
fd663f6
[Automated Commit] Format Codebase
arjunsuresh Jan 15, 2025
6f0d9cb
Fixes for mlc
arjunsuresh Jan 16, 2025
5f3c326
Merge branch 'dev' into mlc
arjunsuresh Jan 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added automation/__init__.py
Empty file.
Empty file added automation/script/__init__.py
Empty file.
71 changes: 52 additions & 19 deletions automation/script/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@
import os
import logging

from cmind.automation import Automation
from cmind import utils
from cmind import __version__ as current_cm_version
from mlc.main import Automation
# from mlc.utils import *
import mlc.utils as utils
from mlc.main import __version__ as current_mlc_version
from utils import *


class CAutomation(Automation):
class ScriptAutomation(Automation):

"""
CM "script" automation actions
(making native scripts more portable, deterministic, reusable and reproducible)
"""

############################################################
def __init__(self, cmind, automation_file):
super().__init__(cmind, __file__)
# super().__init__(cmind, __file__)
super().__init__(cmind, "script", automation_file)
print("Base init over")
logging.basicConfig(level=logging.INFO)
self.os_info = {}
self.run_state = {}
Expand All @@ -33,7 +38,6 @@ def __init__(self, cmind, automation_file):
self.run_state['parent'] = None
self.run_state['version_info'] = []
self.run_state['cache'] = False

self.file_with_cached_state = 'cm-cached-state.json'

self.tmp_file_env = 'tmp-env'
Expand Down Expand Up @@ -224,7 +228,7 @@ def run(self, i):

def _run(self, i):

from cmind import utils
# from cmind import utils
import copy
import time
import shutil
Expand Down Expand Up @@ -258,9 +262,9 @@ def _run(self, i):
'return': 1, 'error': 'Current directory "{}" is not writable - please change it'.format(os.getcwd())}

# Check if has default config
r = self.cmind.access({'action': 'load',
'automation': 'cfg,88dce9c160324c5d',
'artifact': 'default'})
r = self.action_object.access({'action': 'load',
'automation': 'cfg,88dce9c160324c5d',
'artifact': 'default'})
if r['return'] == 0:
config = r['config']

Expand Down Expand Up @@ -336,7 +340,9 @@ def _run(self, i):
'dict2': i['local_' + key],
'append_lists': True,
'append_unique': True})
#print(f"Merged local {key}: {i[key]}")

#print(f"env = {env}")
add_deps = i.get('ad', {})
if not add_deps:
add_deps = i.get('add_deps', {})
Expand Down Expand Up @@ -475,8 +481,9 @@ def _run(self, i):
# Get and cache minimal host OS info to be able to run scripts and
# manage OS environment
if len(self.os_info) == 0:
r = self.cmind.access({'action': 'get_host_os_info',
'automation': 'utils,dc2743f8450541e3'})
r = get_host_os_info()
# r = self.access({'action': 'get_host_os_info',
# 'automation': 'utils,dc2743f8450541e3'})
if r['return'] > 0:
return r

Expand Down Expand Up @@ -527,7 +534,7 @@ def _run(self, i):

tags_string = i.get('tags', '').strip()

ii = utils.sub_input(i, self.cmind.cfg['artifact_keys'])
ii = utils.sub_input(i, self.action_object.cfg['artifact_keys'])

ii['tags'] = tags_string
ii['out'] = None
Expand Down Expand Up @@ -792,6 +799,7 @@ def _run(self, i):
script_artifact = list_of_found_scripts[select_script]

meta = script_artifact.meta
# print(meta)
path = script_artifact.path

# Check min CM version requirement
Expand Down Expand Up @@ -880,7 +888,10 @@ def _run(self, i):
# Force env from meta['env'] as a CONST
# (env OVERWRITE)
script_artifact_env = meta.get('env', {})
#print(f"script meta env= {script_artifact_env}")

env.update(script_artifact_env)
#print(f"env = {env}")

script_artifact_state = meta.get('state', {})
utils.merge_dicts({'dict1': state,
Expand Down Expand Up @@ -1326,9 +1337,12 @@ def _run(self, i):
return r
new_env = r['new_env']

#print(f"env = {env}, new_env={new_env}")
utils.merge_dicts(
{'dict1': env, 'dict2': new_env, 'append_lists': True, 'append_unique': True})

#print(f"merged_env:")
#utils.print_env(env)
new_state = cached_state['new_state']
utils.merge_dicts({'dict1': state,
'dict2': new_state,
Expand Down Expand Up @@ -1664,6 +1678,8 @@ def _run(self, i):
return r

# Check chain of dependencies on other CM scripts
#print(f"before deps: ")
#utils.print_env(env)
if len(deps) > 0:
logging.debug(recursion_spaces +
' - Checking dependencies on other CM scripts:')
Expand All @@ -1681,6 +1697,8 @@ def _run(self, i):
if r['return'] > 0:
return r

#print(f"after deps:")
#utils.print_env(env)
# Clean some output files
clean_tmp_files(clean_files, recursion_spaces)

Expand Down Expand Up @@ -1795,6 +1813,8 @@ def _run(self, i):
if 'preprocess' in dir(customize_code) and not fake_run:

logging.debug(recursion_spaces + ' - Running preprocess ...')
#print(f"preprocess_env:")
#utils.print_env(env)

run_script_input['run_state'] = run_state

Expand Down Expand Up @@ -1958,6 +1978,8 @@ def _run(self, i):
new_state_keys = i['force_new_state_keys']
else:
new_state_keys = new_state_keys_from_meta
#print("Env:")
#utils.print_env(env)

r = detect_state_diff(
env,
Expand Down Expand Up @@ -2836,7 +2858,7 @@ def search(self, i):
i['out'] = None
i['common'] = True

r = super(CAutomation, self).search(i)
r = super(ScriptAutomation, self).search(i)
if r['return'] > 0:
return r

Expand Down Expand Up @@ -3203,7 +3225,10 @@ def add(self, i):
'error': 'file {} not found'.format(script_name)}

# Move tags from input to meta of the newly created script artifact
tags_list = utils.convert_tags_to_list(i)
res = utils.convert_tags_to_list(i['tags'])
if res['return'] > 0:
return res
tags_list = res['tags']
if 'tags' in i:
del (i['tags'])

Expand Down Expand Up @@ -3695,6 +3720,7 @@ def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, a
# Not very efficient but allows logging - can be optimized
# later

#print(f"env about to call deps {d}= {env}")
ii = {
'action': 'run',
'automation': utils.assemble_cm_object(self.meta['alias'], self.meta['uid']),
Expand All @@ -3719,6 +3745,7 @@ def _run_deps(self, deps, clean_env_keys_deps, env, state, const, const_state, a
if d.get(key):
d[key] = {}

#print(f"ii = {ii}, d = {d}")
utils.merge_dicts(
{'dict1': ii, 'dict2': d, 'append_lists': True, 'append_unique': True})

Expand Down Expand Up @@ -3753,12 +3780,18 @@ def _merge_dicts_with_tags(self, dict1, dict2):
return {'return': 0}
for dep in dict1:
if 'tags' in dict1[dep]:
dict1[dep]['tags_list'] = utils.convert_tags_to_list(
dict1[dep])
res = utils.convert_tags_to_list(
dict1[dep]['tags'])
if res['return'] > 0:
return res
dict1[dep]['tags_list'] = res['tags']
for dep in dict2:
if 'tags' in dict2[dep]:
dict2[dep]['tags_list'] = utils.convert_tags_to_list(
dict2[dep])
res = utils.convert_tags_to_list(
dict2[dep]['tags'])
if res['return'] > 0:
return res
dict2[dep]['tags_list'] = res['tags']
utils.merge_dicts({'dict1': dict1, 'dict2': dict2,
'append_lists': True, 'append_unique': True})
for dep in dict1:
Expand Down
Loading
Loading