This file contains hidden or 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
| # Nebius s3 | |
| # sudo apt-get install s3cmd # export the vars below or configure access_key / secret_key | |
| # export AWS_ACCESS_KEY_ID=... | |
| # export AWS_SECRET_ACCESS_KEY=... | |
| # https://s3tools.org/usage | |
| # s3cmd -c ~/.nebius.s3cfg ls | |
| [default] | |
| # access_key=... | |
| # secret_key=... |
This file contains hidden or 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
| # PYTHONPATH=. python ... | |
| import os | |
| import torch | |
| def cuda_oom_hook(device, alloc, device_alloc, device_free, info = dict(counter = 0), snapshot_dump_file_pattern = './memory_snapshot_{pid}_{oom_counter}.pt'): | |
| memory_summary = torch.cuda.memory_summary(device = device) | |
| memory_snapshot = torch.cuda.memory._snapshot(device = device) | |
| pid = os.getpid() | |
| print('device:', device, 'oom#:', info['oom_counter'], 'pid:', pid, 'alloc:', alloc, 'device_alloc:', device_alloc, 'device_free:', device_free) |
This file contains hidden or 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
| import multiprocessing | |
| import itertools | |
| inputs = list(range(111)) | |
| batchsize = 10 | |
| num_workers = 4 | |
| batches = itertools.batched(inputs, batchsize) | |
| def reducer(xs): |
This file contains hidden or 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
| # Usage: bash cache_hf_model.sh Qwen/Qwen3-8B | |
| # export HF_HOME=/my/cache/HF_HOME | |
| python -c 'import sys, transformers; transformers.AutoModel.from_pretrained(sys.argv[-1], trust_remote_code=True, device_map="meta")' $@ |
This file contains hidden or 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
| def load_dotenv(dotenv_path = '.env'): | |
| # https://snarky.ca/use-toml-for-env-files/ | |
| # https://github.com/theskumar/python-dotenv | |
| ''' | |
| # such simple key-value files are toml subset and can be read via tomllib without external packages or hacks | |
| a="b" | |
| c="d" | |
| ''' | |
| import os, tomllib | |
| os.environ.update(tomllib.load(open(dotenv_path, 'rb'))) |
This file contains hidden or 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
| import sys, fsspec | |
| with fsspec.open(sys.argv[1], 'rt') as f: # must pass 'rt' explicitly, as in fsspec the default mode is 'rb' | |
| print(f.read()) # msut use context manager as in fsspec the result of fsspec.open(...) does not have method read() | |
| # echo world > hello.txt | |
| # python catfsspec.py hello.txt | |
| # python catfsspec.py file://hello.txt | |
| # python catfsspec.py s3://mybucket/hello.txt |
This file contains hidden or 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
| # reference: https://gist.github.com/0xjac/85097472043b697ab57ba1b1c7530274 | |
| git clone --bare git@github.com:volcengine/verl.git | |
| cd verl.git | |
| # create a bare repo vadimkantorov/verl | |
| git push --mirror git@github.com:vadimkantorov/verl.git | |
| cd .. && rm -rf verl.git | |
| # set up upstream remote |
This file contains hidden or 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
| # Save as tqdm.py in project dir, then `from tqdm import tqdm; from tqdm.auto import tqdm` should pick up this class, if fails use export PYTHONPATH=. | |
| # Test run: python tqdm.py | |
| import os, sys | |
| # huggingface_hub/hf_api.py: | |
| # from tqdm.auto import tqdm as base_tqdm | |
| # from tqdm.contrib.concurrent import thread_map | |
| # https://tqdm.github.io/docs/shortcuts/#tqdmauto | |
| sys.modules['tqdm.auto'] = sys.modules[__name__] |
This file contains hidden or 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
| # https://github.com/pypa/pip/issues/11440 | |
| # https://github.com/pypa/pip/issues/7822 | |
| # https://stackoverflow.com/a/79598932/445810 | |
| # tomllib is available starting from python --version >= 3.11 | |
| python -m pip install $(python -c 'import tomllib;print(*tomllib.load(open("pyproject.toml","rb"))["project"]["dependencies"])') # --user --break-system-packages |
This file contains hidden or 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
| import http.client | |
| http.client.HTTPConnection.debuglevel = 1 |