Skip to content
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

CM/CMX V3.4.2: new reusable functions #1353

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ CK consists of several sub-projects:
* [CM4ABTF](https://github.com/mlcommons/cm4abtf) - a unified CM interface and automation recipes
to run automotive benchmark across different models, data sets, software and hardware from different vendors.

* [CMX (the next generation of CM)](cm/docs/cmx) - we are developing the next generation of CM
* [CMX (the next generation of CM and CM4MLOps)](cm/docs/cmx) - we are developing the next generation of CM
to make it simpler and more flexible based on user feedback. Please follow
this project [here]( https://github.com/orgs/mlcommons/projects/46 ).

Expand All @@ -59,8 +59,9 @@ CK consists of several sub-projects:

### Maintainers

* CM/CMX/CM4Research: [Grigori Fursin](https://cKnowledge.org/gfursin)
* CM/CM4Research: [Grigori Fursin](https://cKnowledge.org/gfursin)
* CM4MLOps: [Arjun Suresh](https://github.com/arjunsuresh) and [Anandhu Sooraj](https://github.com/anandhu-eng)
* CMX (the next generation of CM) [Grigori Fursin](https://cKnowledge.org/gfursin)

### Citing our project

Expand Down Expand Up @@ -89,11 +90,11 @@ To learn more about the motivation behind CK and CM technology, please explore t

### Acknowledgments

The open-source Collective Knowledge project (CK)
was founded by [Grigori Fursin](https://cKnowledge.org/gfursin),
sponsored by cTuning.org, HiPEAC and OctoML, and donated to MLCommons
to serve the wider community. This open-source initiative includes
CM, CM4MLOps/CM4MLPerf, CM4ABTF, and CMX automation technologies.
Its development is a collaborative community effort,
made possible by our dedicated [volunteers, collaborators,
and contributors](https://github.com/mlcommons/ck/blob/master/CONTRIBUTING.md)!
The open-source Collective Knowledge project (CK, CM, CM4MLOps/CM4MLPerf,
CM4Research and CMX) was created by [Grigori Fursin](https://cKnowledge.org/gfursin)
and sponsored by cTuning.org, OctoAI and HiPEAC.
Grigori donated CK to MLCommons to benefit the community
and to advance its development as a collaborative, community-driven effort.
We thank MLCommons and FlexAI for supporting this project,
as well as our dedicated [volunteers and collaborators](https://github.com/mlcommons/ck/blob/master/CONTRIBUTING.md)
for their feedback and contributions!
6 changes: 5 additions & 1 deletion cm/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## V3.4.1.1
## V3.4.2
- added utils.flatten_dict
- added utils.safe_int
- added utils.safe_float
- added utils.get_set
- added utils.digits

## V3.4.1
- reduced Python min version in pyproject.toml to 3.7 for backwards compatibility
Expand Down
2 changes: 1 addition & 1 deletion cm/cmind/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Written by Grigori Fursin

__version__ = "3.4.1.1"
__version__ = "3.4.2"

from cmind.core import access
from cmind.core import x
Expand Down
105 changes: 105 additions & 0 deletions cm/cmind/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,3 +2047,108 @@ def flatten_dict(d, fd = {}, prefix = ''):
fd[prefix + k] = str(v)

return

##############################################################################
def safe_int(i, d):
"""
Get safe int (useful for sorting function)

Args:
i (any): variable with any type
d (int): default value

Returns:
(int): returns i if it can be converted to int, or d otherwise
"""

r = d
try:
r = int(i)
except Exception as e:
pass

return r

##############################################################################
def safe_float(i, d):
"""
Get safe float (useful for sorting function)

Args:
i (any): variable with any type
d (float): default value

Returns:
(float): returns i if it can be converted to float or d otherwise

"""

r = d
try:
r = float(i)
except Exception as e:
pass

return r

##############################################################################
def get_set(meta, key, state, keys):
"""
Get value from dict and update in another dict

Args:
meta (dict): original dict
key (str): key to get value from original dict
state (dict): target dict
keys (list): list of keys to set value in target dict

Returns:
(Python object): value from original dict or None

"""

v = meta.get(key, None)
if v != None:
cur = state
vv = None
for k in keys:
if k == keys[-1]:
vv = cur.get(k, None)
if vv == None:
cur[k] = v
else:
if k not in cur:
cur[k] = {}
cur = cur[k]

return v

##############################################################################
def digits(s, first = True):
"""
Get first digits and convert to int

Args:
s (str): string ("1.3+xyz")
first (bool): if True, choose only first digits, otherwise all

Returns:
(int): returns int from first digits or 0

"""

v = 0

digits = ''
for char in s:
if char.isdigit():
digits+=char
elif first:
break

try:
v = int(digits)
except Exception as e:
pass

return v
Loading