File size: 1,361 Bytes
d0cd3b0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
import os
import yaml

def conf_editor(config_path):

    class IndentDumper(yaml.Dumper):
        def increase_indent(self, flow=False, indentless=False):
            return super(IndentDumper, self).increase_indent(flow, False)


    def tuple_constructor(loader, node):
        # Load the sequence of values from the YAML node
        values = loader.construct_sequence(node)
        # Return a tuple constructed from the sequence
        return tuple(values)

    # Register the constructor with PyYAML  
    yaml.SafeLoader.add_constructor('tag:yaml.org,2002:python/tuple',
tuple_constructor)



    def conf_edit(config_path):
        with open(config_path, 'r') as f:
            data = yaml.load(f, Loader=yaml.SafeLoader)

        # handle cases where 'use_amp' is missing from config:
        if 'use_amp' not in data.keys():
          data['training']['use_amp'] = True

        if data['inference']['num_overlap'] != 2:
          data['inference']['num_overlap'] = 2

        if data['inference']['batch_size'] == 1:
          data['inference']['batch_size'] = 2

        print("Using custom overlap and chunk_size values:")
        print(f"batch_size = {data['inference']['batch_size']}")


        with open(config_path, 'w') as f:
            yaml.dump(data, f, default_flow_style=False, sort_keys=False, Dumper=IndentDumper, allow_unicode=True)