Create a directory and exist ok:
import pathlib
# create parent of a file
pathlib.Path('file_path').parent.mkdir(parents=True, exist_ok=True)
# create directory
pathlib.Path('directory_path').mkdir(parents=True, exist_ok=True)| from transformers import ( | |
| AutoTokenizer, | |
| LEDConfig, | |
| LEDForConditionalGeneration, | |
| ) | |
| from datasets import load_dataset | |
| import random | |
| random.seed(2) |
| ``` | |
| g batch of size torch.Size([2407, 2]) because not full seq_len of 16384 | |
| ---------------------------------------------------------------------------------------------------- | |
| | Eval 354 at step 88500 | time: 1345.55s | valid loss 0.74 | bpc 1.07357 | |
| ---------------------------------------------------------------------------------------------------- | |
| | epoch 130 step 88510 | 16 batches | lr 0.000442 | ms/batch 11917.46 | loss 0.75 | bpc 1.07888 | |
| | epoch 130 step 88520 | 26 batches | lr 0.000442 | ms/batch 5110.18 | loss 0.78 | bpc 1.12858 | |
| | epoch 130 step 88530 | 36 batches | lr 0.000442 | ms/batch 5107.78 | loss 0.71 | bpc 1.02528 | |
| | epoch 130 step 88540 | 46 batches | lr 0.000442 | ms/batch 5109.07 | loss 0.74 | bpc 1.07031 | |
| | epoch 130 step 88550 | 56 batches | lr 0.000442 | ms/batch 5111.60 | loss 0.78 | bpc 1.12227 |
| import typing | |
| def return_dict_structure(obj): | |
| """Return the structure of a possibly nested dictionary object.""" | |
| new_obj = {} | |
| if isinstance(obj, typing.List) or isinstance(obj, typing.Tuple): | |
| if obj: | |
| return [return_dict_structure(obj[0]), '...'] | |
| else: |
| #!/usr/bin/python | |
| import sys | |
| def format_block(txt, maxlen=79, indent=2): | |
| lines = txt.replace('\n',' ') | |
| res = [] | |
| line = '' | |
| tokens = [e for e in lines.split(' ') if e] | |
| i=0 | |
| lineno=0 |
| # add this to ~/.ipython/profile_default/startup/start.py | |
| import os | |
| import sys | |
| import re | |
| from collections import Counter, defaultdict, namedtuple | |
| import itertools | |
| import json | |
| import numpy as np | |
| import gzip |
You need to have pv installed.
Command:
tar -cf - [Source directory] -P | pv -s $(du -sb [Source dir] | awk '{print $1}') | gzip > [Dest tar.gz file]Example:
tar -cf - dir/ -P | pv -s $(du -sb dir/ | awk '{print $1}') | gzip > file.tar.gz| from argparse import ArgumentParser | |
| ap = ArgumentParser() | |
| ap.add_argument('--verbose', '-v', action='store_true', default=False) | |
| args = ap.parse_args() | |
| imoprt logging | |
| log = logging.getLogger(__name__) | |
| if args.verbose: | |
| log.basicConfig(format="%(levelname)s: %(message)s", level=log.DEBUG) |
| import sys | |
| import tensorflow as tf | |
| def main(n): | |
| """ Calculate the n-th Fibonacci number """ | |
| if n < 1: | |
| print('n should be greater than 0') | |
| sys.exit(1) | |
| elif n == 1 or n == 2: |