Text Generation
PEFT
Safetensors
PyTorch
English
causal-lm
lora
qwen
sft
dpo
seal
self-adaptation
hitl
Instructions to use aaronr43210/MiniSEAL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use aaronr43210/MiniSEAL with PEFT:
Task type is invalid.
- Notebooks
- Google Colab
- Kaggle
Download src/common/utils.py from aaronr43210/MiniSEAL: direct link, hf CLI and curl.
- Browser
- Download file 1.48 kB
-
https://huggingface.co/aaronr43210/MiniSEAL/resolve/main/src/common/utils.py
- Command line
-
hf download hf://aaronr43210/MiniSEAL/src/common/utils.py
-
curl -L -o utils.py https://huggingface.co/aaronr43210/MiniSEAL/resolve/main/src/common/utils.py
1.48 kB
| from typing import Union | |
| import json | |
| import os | |
| import random | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| def ensure_dir(path: Union[str, Path]) -> None: | |
| """ | |
| Input: | |
| path: Directory path. | |
| Output: | |
| Creates the directory if it does not exist. | |
| """ | |
| Path(path).mkdir(parents=True, exist_ok=True) | |
| def save_json(obj: dict, path: Union[str, Path]) -> None: | |
| """ | |
| Input: | |
| obj: Python dictionary. | |
| path: Output JSON path. | |
| Output: | |
| Saves dictionary as formatted JSON. | |
| """ | |
| with open(path, "w", encoding="utf-8") as f: | |
| json.dump(obj, f, indent=2, ensure_ascii=False) | |
| def load_json(path: Union[str, Path]) -> dict: | |
| """ | |
| Input: | |
| path: JSON file path. | |
| Output: | |
| Loaded Python dictionary. | |
| """ | |
| with open(path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def set_seed(seed: int) -> None: | |
| """ | |
| Input: | |
| seed: Integer seed. | |
| Output: | |
| Makes Python, NumPy, and PyTorch randomness more reproducible. | |
| """ | |
| random.seed(seed) | |
| np.random.seed(seed) | |
| torch.manual_seed(seed) | |
| torch.cuda.manual_seed_all(seed) | |
| def is_rank_zero() -> bool: | |
| """ | |
| Output: | |
| True only for the main distributed process. | |
| """ | |
| return int(os.environ.get("RANK", "0")) == 0 | |
| def get_world_size() -> int: | |
| """ | |
| Output: | |
| Number of distributed processes. | |
| """ | |
| return int(os.environ.get("WORLD_SIZE", "1")) | |