()
| 278 | |
| 279 | |
| 280 | def main(): |
| 281 | # See all possible arguments in src/transformers/training_args.py |
| 282 | # or by passing the --help flag to this script. |
| 283 | # We now keep distinct sets of args, for a cleaner separation of concerns. |
| 284 | |
| 285 | parser = HfArgumentParser((ModelArguments, DataTrainingArguments, TrainingArguments)) |
| 286 | if len(sys.argv) == 2 and sys.argv[1].endswith(".json"): |
| 287 | # If we pass only one argument to the script and it's the path to a json file, |
| 288 | # let's parse it to get our arguments. |
| 289 | model_args, data_args, training_args = parser.parse_json_file(json_file=os.path.abspath(sys.argv[1])) |
| 290 | else: |
| 291 | model_args, data_args, training_args = parser.parse_args_into_dataclasses() |
| 292 | |
| 293 | # Setup logging |
| 294 | logging.basicConfig( |
| 295 | format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", |
| 296 | datefmt="%m/%d/%Y %H:%M:%S", |
| 297 | handlers=[logging.StreamHandler(sys.stdout)], |
| 298 | ) |
| 299 | |
| 300 | if training_args.should_log: |
| 301 | # The default of training_args.log_level is passive, so we set log level at info here to have that default. |
| 302 | transformers.utils.logging.set_verbosity_info() |
| 303 | |
| 304 | log_level = training_args.get_process_log_level() |
| 305 | logger.setLevel(log_level) |
| 306 | datasets.utils.logging.set_verbosity(log_level) |
| 307 | transformers.utils.logging.set_verbosity(log_level) |
| 308 | transformers.utils.logging.enable_default_handler() |
| 309 | transformers.utils.logging.enable_explicit_format() |
| 310 | |
| 311 | # Log on each process the small summary: |
| 312 | logger.warning( |
| 313 | f"Process rank: {training_args.local_process_index}, device: {training_args.device}, n_gpu: {training_args.n_gpu}, " |
| 314 | + f"distributed training: {training_args.parallel_mode.value == 'distributed'}, 16-bits training: {training_args.fp16}" |
| 315 | ) |
| 316 | logger.info(f"Training/evaluation parameters {training_args}") |
| 317 | |
| 318 | # Set seed before initializing model. |
| 319 | set_seed(training_args.seed) |
| 320 | |
| 321 | # Get the datasets: you can either provide your own CSV/JSON/TXT training and evaluation files (see below) |
| 322 | # or just provide the name of one of the public datasets available on the hub at https://huggingface.co/datasets/ |
| 323 | # (the dataset will be downloaded automatically from the datasets Hub). |
| 324 | # |
| 325 | # For CSV/JSON files, this script will use the column called 'text' or the first column if no column called |
| 326 | # 'text' is found. You can easily tweak this behavior (see below). |
| 327 | # |
| 328 | # In distributed training, the load_dataset function guarantee that only one local process can concurrently |
| 329 | # download the dataset. |
| 330 | if data_args.dataset_name is not None: |
| 331 | # Downloading and loading a dataset from the hub. |
| 332 | raw_datasets = load_dataset( |
| 333 | data_args.dataset_name, |
| 334 | data_args.dataset_config_name, |
| 335 | cache_dir=model_args.cache_dir, |
| 336 | token=model_args.token, |
| 337 | streaming=data_args.streaming, |
no test coverage detected