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