job_function_util.py 1.2 KB
Newer Older
S
ShawnXuan 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
"""
Copyright 2020 The OneFlow Authors. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
S
ShawnXuan 已提交
16 17 18

import oneflow as flow

M
format  
mir-of 已提交
19

S
ShawnXuan 已提交
20 21
def _default_config(args):
    config = flow.function_config()
22
    config.default_logical_view(flow.scope.consistent_view())
S
ShawnXuan 已提交
23
    config.default_data_type(flow.float)
S
ShawnXuan 已提交
24 25
    if args.use_fp16:
        config.enable_auto_mixed_precision(True)
T
tsai 已提交
26 27
    if args.use_xla:
        config.use_xla_jit(True)
S
ShawnXuan 已提交
28 29
    return config

M
format  
mir-of 已提交
30

S
ShawnXuan 已提交
31 32
def get_train_config(args):
    train_config = _default_config(args)
F
Flowingsun007 已提交
33
    train_config.cudnn_conv_heuristic_search_algo(False)
S
ShawnXuan 已提交
34

M
format  
mir-of 已提交
35

S
ShawnXuan 已提交
36
    train_config.prune_parallel_cast_ops(True)
S
ShawnXuan 已提交
37 38 39
    train_config.enable_inplace(True)
    return train_config

M
format  
mir-of 已提交
40

S
ShawnXuan 已提交
41
def get_val_config(args):
42
    return _default_config(args)