forked from analogdevicesinc/ai8x-training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_qat_yaml.py
34 lines (28 loc) · 1.03 KB
/
parse_qat_yaml.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
###################################################################################################
#
# Copyright (C) 2020-2021 Maxim Integrated Products, Inc. All Rights Reserved.
#
# Maxim Integrated Products, Inc. Default Copyright Notice:
# https://www.maximintegrated.com/en/aboutus/legal/copyrights.html
#
###################################################################################################
"""
Parses YAML file used to define Quantization Aware Training
"""
import yaml
def parse(yaml_file):
"""
Parses `yaml_file` that defines the QAT policy
"""
policy = None
with open(yaml_file, mode='r', encoding='utf-8') as stream:
try:
policy = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
print(policy)
if policy and 'start_epoch' not in policy:
assert False, '`start_epoch` must be defined in QAT policy'
if policy and 'weight_bits' not in policy:
assert False, '`weight_bits` must be defined in QAT policy'
return policy