| 1 |
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 |
# See https://llvm.org/LICENSE.txt for license information. |
| 3 |
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 |
r"""Combine multiple training corpus into a single training corpus. |
| 5 |
|
| 6 |
Currently only support the case that multiple corpus share the same |
| 7 |
configurables except the "modules" field. |
| 8 |
|
| 9 |
Usage: we'd like to combine training corpus corpus1 and corpus2 into |
| 10 |
combinedcorpus; we first structure the files as follows: |
| 11 |
|
| 12 |
combinedcorpus |
| 13 |
combinedcorpus/corpus1 |
| 14 |
combinedcorpus/corpus2 |
| 15 |
|
| 16 |
Running this script with |
| 17 |
|
| 18 |
python3 \ |
| 19 |
compiler_opt/tools/combine_training_corpus.py \ |
| 20 |
--root_dir=$PATH_TO_combinedcorpus |
| 21 |
|
| 22 |
generates combinedcorpus/corpus_description.json file. In this way corpus1 |
| 23 |
and corpus2 are combined into combinedcorpus. |
| 24 |
""" |
| 25 |
|
| 26 |
import argparse |
| 27 |
import logging |
| 28 |
|
| 29 |
from mlgo.corpus import combine_training_corpus_lib |
| 30 |
from mlgo.corpus import flags |
| 31 |
|
| 32 |
|
| 33 |
def parse_args_and_run(): |
| 34 |
parser = argparse.ArgumentParser( |
| 35 |
description="A tool for combining multiple training corpora" |
| 36 |
) |
| 37 |
parser.add_argument( |
| 38 |
"--root_dir", type=str, help="The root dir of module paths to combine." |
| 39 |
) |
| 40 |
flags.add_verbosity_arguments(parser) |
| 41 |
args = parser.parse_args() |
| 42 |
main(args) |
| 43 |
|
| 44 |
|
| 45 |
def main(args): |
| 46 |
logging.basicConfig(level=args.verbosity) |
| 47 |
|
| 48 |
combine_training_corpus_lib.combine_corpus(args.root_dir) |
| 49 |
|
| 50 |
|
| 51 |
if __name__ == "__main__": |
| 52 |
parse_args_and_run() |