Created
December 29, 2021 18:22
-
-
Save stas00/1a7b00488bb3be3aa05aa9d27fad72c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# this program takes as its input cmd line args and it reformats them into a nice 80-char width that | |
# can be easily added to docs or forums. | |
# | |
# Example: | |
# | |
# cmd-wrap CUDA_VISIBLE_DEVICES=0 python ./examples/pytorch/translation/run_translation.py --model_name_or_path t5-small --output_dir output_dir --do_train --label_smoothing 0.1 --logging_strategy no --save_strategy no --per_device_train_batch_size 32 --max_source_length 512 --max_target_length 512 --num_train_epochs 1 --overwrite_output_dir --source_lang en --target_lang ro --dataset_name wmt16 --dataset_config "ro-en" --source_prefix "translate English to Romanian: " --warmup_steps 50 --max_train_samples 2001 --dataloader_num_workers 2 | |
# | |
# CUDA_VISIBLE_DEVICES=0 python \ | |
# ./examples/pytorch/translation/run_translation.py --model_name_or_path \ | |
# t5-small --output_dir output_dir --do_train --label_smoothing 0.1 \ | |
# --logging_strategy no --save_strategy no --per_device_train_batch_size 32 \ | |
# --max_source_length 512 --max_target_length 512 --num_train_epochs 1 \ | |
# --overwrite_output_dir --source_lang en --target_lang ro --dataset_name wmt16 \ | |
# --dataset_config ro-en --source_prefix 'translate English to Romanian: ' \ | |
# --warmup_steps 50 --max_train_samples 2001 --dataloader_num_workers 2 | |
import os | |
import shlex | |
import sys | |
def wrap_orig_cmd(max_width=80): | |
""" | |
Return the original command line string that can be replayed nicely and wrapped for 80 char width | |
Args: | |
- max_width: the width to wrap for. defaults to 80 | |
""" | |
cmd = list(map(shlex.quote, sys.argv))[1:] | |
# split up into up to max_width lines with shell multi-line escapes | |
lines = [] | |
current_line = "" | |
while len(cmd) > 0: | |
current_line += f"{cmd.pop(0)} " | |
if len(cmd) == 0 or len(current_line) + len(cmd[0]) + 1 > max_width - 1: | |
lines.append(current_line) | |
current_line = "" | |
return "\\\n".join(lines) | |
print(wrap_orig_cmd()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment