Skip to content

Commit 2c18fe3

Browse files
authored
V0.0.1 pre (#18)
* Rename library to optimum * Added project URL.
1 parent f2b23fd commit 2c18fe3

17 files changed

+759
-759
lines changed

README.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
[![ONNX Runtime](https://github.com/huggingface/optimus/actions/workflows/test-onnxruntime.yml/badge.svg)](https://github.com/huggingface/optimus/actions/workflows/test-onnxruntime.yml)
2-
[![LPOT](https://github.com/huggingface/optimus/actions/workflows/test-intel.yml/badge.svg)](https://github.com/huggingface/optimus/actions/workflows/test-intel.yml)
1+
[![ONNX Runtime](https://github.com/huggingface/optimum/actions/workflows/test-onnxruntime.yml/badge.svg)](https://github.com/huggingface/optimum/actions/workflows/test-onnxruntime.yml)
2+
[![LPOT](https://github.com/huggingface/optimum/actions/workflows/test-intel.yml/badge.svg)](https://github.com/huggingface/optimum/actions/workflows/test-intel.yml)
33

4-
# Optimus
4+
# Optimum
55

66
## Install
77
To install the latest release of this package:
88

9-
`pip install optimus`
9+
`pip install optimum`
1010

1111
or from current main branch:
1212

13-
`pip install https://github.com/huggingface/optimus.git`
13+
`pip install https://github.com/huggingface/optimum.git`
1414

1515
or for development, clone the repo and install it from the local copy:
1616

1717
```
18-
git clone https://github.com/huggingface/optimus.git
19-
cd optimus
18+
git clone https://github.com/huggingface/optimum.git
19+
cd optimum
2020
pip install -e .
2121
```
2222

2323

2424
## Usage
2525
Convert a hub model:
26-
`optimus_convert`
26+
`optimum_convert`
2727

2828
Optimize a hub model:
29-
`optimus_optimize`
29+
`optimum_optimize`
3030

3131
Apply LPOT quantization:
3232

examples/pytorch/text-classification/run_glue.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ def train_func(model):
511511
if not training_args.do_eval:
512512
raise ValueError("do_eval must be set to True for quantization.")
513513

514-
from optimus.intel.lpot import LpotQuantizer, LpotQuantizationMode, LpotConfig
514+
from optimum.intel.lpot import LpotQuantizer, LpotQuantizationMode, LpotConfig
515515

516516
q8_config = LpotConfig.from_pretrained(
517517
model_args.config_name_or_path if model_args.config_name_or_path is not None else default_config,

setup.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import re
22
from setuptools import find_packages, setup
33

4-
# Ensure we match the version set in optimus/version.py
4+
# Ensure we match the version set in optimum/version.py
55
try:
6-
filepath = './src/optimus/version.py'
6+
filepath = 'src/optimum/version.py'
77
with open( filepath ) as version_file:
88
__version__, = re.findall('__version__ = "(.*)"', version_file.read())
99
except Exception as error:
@@ -28,9 +28,9 @@
2828
}
2929

3030
setup(
31-
name="optimus",
31+
name="optimum",
3232
version=__version__,
33-
description="Optimus Library is an extension of the Hugging Face Transformers library, providing a framework to "
33+
description="Optimum Library is an extension of the Hugging Face Transformers library, providing a framework to "
3434
"integrate third-party libraries from Hardware Partners and interface with their specific "
3535
"functionality.",
3636
long_description=open("README.md", "r", encoding="utf-8").read(),
@@ -47,7 +47,7 @@
4747
"Topic :: Scientific/Engineering :: Artificial Intelligence",
4848
],
4949
keywords="transformers, quantization, pruning, training, ipu",
50-
url="",
50+
url="hf.co/hardware",
5151
author="HuggingFace Inc. Special Ops Team",
5252
author_email="hardware@huggingface.co",
5353
license="Apache",
@@ -57,9 +57,9 @@
5757
extras_require=extras,
5858
entry_points={
5959
"console_scripts": [
60-
"optimus_export=optimus.onnxruntime.convert:main",
61-
"optimus_optimize=optimus.onnxruntime.optimize_model:main",
62-
"optimus_export_optimize=optimus.onnxruntime.convert_and_optimize:main"
60+
"optimum_export=optimum.onnxruntime.convert:main",
61+
"optimum_optimize=optimum.onnxruntime.optimize_model:main",
62+
"optimum_export_optimize=optimum.onnxruntime.convert_and_optimize:main"
6363
],
6464
},
6565
include_package_data=True,
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
1-
import os
2-
import requests
3-
import yaml
4-
from functools import reduce
5-
from huggingface_hub import hf_hub_download
6-
from typing import Any, Optional, Union
7-
8-
9-
class LpotConfig:
10-
11-
def __init__(
12-
self,
13-
config_path: str,
14-
save_path: Optional[str] = None,
15-
overwrite: Optional[bool] = False,
16-
):
17-
"""
18-
Args:
19-
config_path (:obj:`str`):
20-
Path to the YAML configuration file used to control the tuning behavior.
21-
save_path (:obj:`str`, `optional`):
22-
Path used to save the configuration file.
23-
overwrite (:obj:`bool`, `optional`):
24-
Whether or not overwrite the configuration file when the latter is modified and saved.
25-
Returns:
26-
config: LpotConfig object.
27-
"""
28-
29-
self.path = config_path
30-
self.config = self._read_config()
31-
self.save_path = save_path
32-
self.overwrite = overwrite
33-
34-
def _read_config(self):
35-
with open(self.path, 'r') as f:
36-
try:
37-
config = yaml.safe_load(f)
38-
except yaml.YAMLError as exc:
39-
print(exc)
40-
return config
41-
42-
def get_config(self, keys: str):
43-
return reduce(lambda d, key: d.get(key) if d else None, keys.split("."), self.config)
44-
45-
def set_config(self, keys: str, value: Any):
46-
d = self.config
47-
keys = keys.split('.')
48-
for key in keys[:-1]:
49-
d = d.setdefault(key, {})
50-
d[keys[-1]] = value
51-
self._save_pretrained()
52-
53-
def _save_pretrained(self):
54-
if self.save_path is None and not self.overwrite:
55-
raise ValueError("Needs either path or overwrite set to True.")
56-
57-
self.path = self.save_path if self.save_path is not None else self.path
58-
with open(self.path, "w") as f:
59-
yaml.dump(self.config, f)
60-
61-
@classmethod
62-
def from_pretrained(
63-
cls,
64-
config_name_or_path: Union[str, os.PathLike],
65-
config_name: str,
66-
cache_dir: Optional[Union[str, os.PathLike]] = None,
67-
**config_kwargs
68-
):
69-
"""
70-
Instantiate a LpotConfig object from a configuration file which can either be hosted on
71-
huggingface.co or from a local directory path.
72-
73-
Args:
74-
config_name_or_path (:obj:`Union[str, os.PathLike]`):
75-
Repository name in the Hub or path to a local directory containing the configuration file.
76-
config_name (:obj:`str`):
77-
Name of the configuration file.
78-
cache_dir (:obj:`Union[str, os.PathLike]`, `optional`):
79-
Path to a directory in which a downloaded configuration should be cached if the standard cache should
80-
not be used.
81-
config_kwargs (:obj:`Dict`, `optional`):
82-
config_kwargs will be passed to the LpotConfig object during initialization.
83-
Returns:
84-
config: LpotConfig object.
85-
"""
86-
87-
revision = None
88-
if len(config_name_or_path.split("@")) == 2:
89-
config_name_or_path, revision = config_name_or_path.split("@")
90-
91-
if os.path.isdir(config_name_or_path) and config_name in os.listdir(config_name_or_path):
92-
config_file = os.path.join(config_name_or_path, config_name)
93-
else:
94-
try:
95-
config_file = hf_hub_download(
96-
repo_id=config_name_or_path,
97-
filename=config_name,
98-
revision=revision,
99-
cache_dir=cache_dir,
100-
)
101-
except requests.exceptions.RequestException:
102-
raise ValueError(f"{config_name} NOT FOUND in HuggingFace Hub")
103-
104-
config = cls(config_file, **config_kwargs)
105-
return config
106-
1+
import os
2+
import requests
3+
import yaml
4+
from functools import reduce
5+
from huggingface_hub import hf_hub_download
6+
from typing import Any, Optional, Union
7+
8+
9+
class LpotConfig:
10+
11+
def __init__(
12+
self,
13+
config_path: str,
14+
save_path: Optional[str] = None,
15+
overwrite: Optional[bool] = False,
16+
):
17+
"""
18+
Args:
19+
config_path (:obj:`str`):
20+
Path to the YAML configuration file used to control the tuning behavior.
21+
save_path (:obj:`str`, `optional`):
22+
Path used to save the configuration file.
23+
overwrite (:obj:`bool`, `optional`):
24+
Whether or not overwrite the configuration file when the latter is modified and saved.
25+
Returns:
26+
config: LpotConfig object.
27+
"""
28+
29+
self.path = config_path
30+
self.config = self._read_config()
31+
self.save_path = save_path
32+
self.overwrite = overwrite
33+
34+
def _read_config(self):
35+
with open(self.path, 'r') as f:
36+
try:
37+
config = yaml.safe_load(f)
38+
except yaml.YAMLError as exc:
39+
print(exc)
40+
return config
41+
42+
def get_config(self, keys: str):
43+
return reduce(lambda d, key: d.get(key) if d else None, keys.split("."), self.config)
44+
45+
def set_config(self, keys: str, value: Any):
46+
d = self.config
47+
keys = keys.split('.')
48+
for key in keys[:-1]:
49+
d = d.setdefault(key, {})
50+
d[keys[-1]] = value
51+
self._save_pretrained()
52+
53+
def _save_pretrained(self):
54+
if self.save_path is None and not self.overwrite:
55+
raise ValueError("Needs either path or overwrite set to True.")
56+
57+
self.path = self.save_path if self.save_path is not None else self.path
58+
with open(self.path, "w") as f:
59+
yaml.dump(self.config, f)
60+
61+
@classmethod
62+
def from_pretrained(
63+
cls,
64+
config_name_or_path: Union[str, os.PathLike],
65+
config_name: str,
66+
cache_dir: Optional[Union[str, os.PathLike]] = None,
67+
**config_kwargs
68+
):
69+
"""
70+
Instantiate a LpotConfig object from a configuration file which can either be hosted on
71+
huggingface.co or from a local directory path.
72+
73+
Args:
74+
config_name_or_path (:obj:`Union[str, os.PathLike]`):
75+
Repository name in the Hub or path to a local directory containing the configuration file.
76+
config_name (:obj:`str`):
77+
Name of the configuration file.
78+
cache_dir (:obj:`Union[str, os.PathLike]`, `optional`):
79+
Path to a directory in which a downloaded configuration should be cached if the standard cache should
80+
not be used.
81+
config_kwargs (:obj:`Dict`, `optional`):
82+
config_kwargs will be passed to the LpotConfig object during initialization.
83+
Returns:
84+
config: LpotConfig object.
85+
"""
86+
87+
revision = None
88+
if len(config_name_or_path.split("@")) == 2:
89+
config_name_or_path, revision = config_name_or_path.split("@")
90+
91+
if os.path.isdir(config_name_or_path) and config_name in os.listdir(config_name_or_path):
92+
config_file = os.path.join(config_name_or_path, config_name)
93+
else:
94+
try:
95+
config_file = hf_hub_download(
96+
repo_id=config_name_or_path,
97+
filename=config_name,
98+
revision=revision,
99+
cache_dir=cache_dir,
100+
)
101+
except requests.exceptions.RequestException:
102+
raise ValueError(f"{config_name} NOT FOUND in HuggingFace Hub")
103+
104+
config = cls(config_file, **config_kwargs)
105+
return config
106+

0 commit comments

Comments
 (0)