Hub documentation
Zephon
Zephon
Zephon์ DatologyAI๊ฐ ๊ฐ๋ฐํ foundation model ํ์ต์ฉ ๋ฐ์ดํฐ ๋ก๋์
๋๋ค. ํ์ต์ด ์งํ๋๋ ๋์ ๋ฐ์ดํฐ๋ฅผ ํ ํฐํ, ํจํน ๋ฐ ํผํฉํ๋ฉฐ, GPU ์๋ฅผ ๋ณ๊ฒฝํด๋ ๋์ผํ ๋ฐฐ์น(elastic determinism)๋ฅผ ์ ๊ณตํฉ๋๋ค. Zephon์ hf:// ๊ฒฝ๋ก๋ฅผ ํตํด Hugging Face Hub์์ ๋ฐ์ดํฐ๋ฅผ ์ง์ ์ฝ์ต๋๋ค.
์ค์น
hf extra๋ Hub ๋ฐ์ดํฐ์
๋ฐ Parquet ํ์ผ์ ๋ํ ์ง์์ ์ถ๊ฐํฉ๋๋ค. ์๋ ์์ ๋ ํ ํฐํ๋ฅผ ์ํด transformers๋ ํ์ํฉ๋๋ค:
pip install "zephon[hf]" transformersHub์์ ๋ฐ์ดํฐ์ ๋ก๋
hf:// ๊ฒฝ๋ก๋ฅผ Dataset.from_path์ ์ ๋ฌํฉ๋๋ค. ์ด ๊ฒฝ๋ก๋ ๋ฐ์ดํฐ์
, ๊ตฌ์ฑ ๋ฐ ์คํ๋ฆฟ์ ์ง์ ํ๋ฉฐ, ์๋ฅผ ๋ค์ด HuggingFaceFW/fineweb-edu์ sample-10BT ๊ตฌ์ฑ์ train ์คํ๋ฆฟ์ ๋ํ๋
๋๋ค.
Zephon์ shard cache๋ฅผ ํตํด Hub ๋ฐ์ดํฐ์
์ ์ฝ์ผ๋ฏ๋ก ์บ์๋ฅผ ํ์ฑํํด์ผ ํฉ๋๋ค. ์บ์๋ฅผ ๋น ๋ฅธ ๋ก์ปฌ ๋์คํฌ์ ๋๊ณ ํฌ๊ธฐ ์ ํ์ ์ค์ ํ์ธ์:
from zephon import Pipeline
from zephon.io import CacheOptions, Dataset, StoreOptions
from zephon.work import MixtureSpec, StaticMixtureWorkSource
dataset = Dataset.from_path("fineweb_edu", "hf://HuggingFaceFW/fineweb-edu/sample-10BT/train")
work_source = StaticMixtureWorkSource(
datasets=[dataset],
mixture=MixtureSpec({"fineweb_edu": 1.0}),
seed=42,
)
cache = CacheOptions(enabled=True, root="/tmp/zephon-cache", limit_bytes=50 << 30) # 50 GiB
pipeline = (
Pipeline(work_source)
.options(io_options=StoreOptions(cache=cache))
.tokenize(tokenizer_id="gpt2", field="text")
.pack_flat(max_length=2049, algorithm="wrap")
.batch(microbatch_size=8)
)
for batch in pipeline:
tensors = batch.to_training(return_labels=True)
print(tensors["input_ids"].shape, tensors["labels"].shape) # (8, 2048) (8, 2048)
breaktokenize๋ text ์ปฌ๋ผ์ ํ ํฐ ID๋ก ๋ณํํฉ๋๋ค. pack_flat๋ ํ ํฐํ๋ ๋ฌธ์๋ฅผ max_length ํ ํฐ ๊ธธ์ด์ ์ํ์ค๋ก ๊ฒฐํฉํฉ๋๋ค. max_length๋ฅผ ์ปจํ
์คํธ ๊ธธ์ด๋ณด๋ค 1 ํฐ ๊ฐ์ผ๋ก ์ค์ ํ์ธ์. return_labels=True์ธ ๊ฒฝ์ฐ to_training์ ๋ผ๋ฒจ์ ํ ์์น๋งํผ ์ด๋์ํค๋ฏ๋ก, input_ids์ labels ๋ชจ๋ ์ปจํ
์คํธ ๊ธธ์ด๋ฅผ ๊ฐ๊ฒ ๋ฉ๋๋ค.
Pipeline๋ Python ๋ฐ๋ณต ๊ฐ๋ฅ ๊ฐ์ฒด(iterable)์ด๋ฏ๋ก ๋ชจ๋ ํ์ต ๋ฃจํ์์ ์ฌ์ฉํ ์ ์์ต๋๋ค. Zephon์ ์ฝ๊ธฐ ์ ์ ์ ์ฒด ์ค๋(shard)๋ฅผ ๋ค์ด๋ก๋ํ๋ฏ๋ก ์ฒซ ๋ฒ์งธ ๋ฐฐ์น(batch)๋ฅผ ๊ฐ์ ธ์ค๋ ๋ฐ ์๊ฐ์ด ๊ฑธ๋ฆด ์ ์์ต๋๋ค.
๊ฐ์ธ ๋๋ ๊ฒ์ดํธ๋ ๋ฐ์ดํฐ์
์ ์ฝ์ผ๋ ค๋ฉด ๋จผ์ Hugging Face ๊ณ์ ์ผ๋ก ๋ก๊ทธ์ธํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด hf auth login์ ์ฌ์ฉํ ์ ์์ต๋๋ค. Zephon์ HF_TOKEN ํ๊ฒฝ ๋ณ์๋ ์ฝ์ต๋๋ค.
๊ฒฝ๋ก ํ์
Zephon์ Hub ๋ฐ์ดํฐ์
์ ๋ํ hf:// ๊ฒฝ๋ก๋ ๋ค์๊ณผ ๊ฐ์ ํ์์ ๊ฐ์ง๋๋ค:
hf://{org}/{name}[@[{revision}][~{source}]]/[{config}/]{split}revision: ๋ธ๋์น, ํ๊ทธ ๋๋ ์ปค๋ฐ์ ๋๋ค. ๊ธฐ๋ณธ๊ฐ์main์ ๋๋ค. Zephon์ ๋ฐ์ดํฐ์ ์ ๋ก๋ํ ๋ ๊ฒฝ๋ก๋ฅผ ํน์ ์ปค๋ฐ์ ๊ณ ์ ํ๋ฏ๋ก ๋ชจ๋ ๋ญํฌ๊ฐ ๋์ผํ ํ์ผ์ ์ฝ์ต๋๋ค.source:original์ ์ ์ฅ์์ ์ ๋ก๋๋ ํ์ผ์ ์ฝ๊ณ ,parquet๋ Hub์ ์๋ Parquet ๋ณํ์ ์ฝ์ต๋๋ค. ์์ค๋@๋ค์ ์ง์ ํ๋ฉฐ, ์๋ฅผ ๋ค์ด@~parquet์ ๊ฐ์ด ์ฌ์ฉํฉ๋๋ค. ๊ธฐ๋ณธ์ ์ผ๋ก Zephon์ ํด๋น ํฌ๋งท์ ์ง์ํ ๊ฒฝ์ฐ ์ ๋ก๋๋ ํ์ผ์ ์ฝ๊ณ , ์ง์ํ์ง ์์ ๊ฒฝ์ฐ Parquet ๋ณํ์ ์ฌ์ฉํฉ๋๋ค.config: ๋ฐ์ดํฐ์ ๊ตฌ์ฑ. ๋ฐ์ดํฐ์ ์ ๊ตฌ์ฑ์ด ํ๋ ์ด์ ์๋ ๊ฒฝ์ฐ ํฌํจํฉ๋๋ค.
| ๊ฒฝ๋ก | ์ฝ๊ธฐ |
|---|---|
hf://HuggingFaceFW/fineweb-edu/sample-10BT/train | main ๋ธ๋์น์ sample-10BT ๊ตฌ์ฑ์์ train ๋ถํ |
hf://HuggingFaceFW/fineweb-edu@v1.4.0/sample-10BT/train | v1.4.0 ๋ธ๋์น์์ ๋์ผํ ๋ถ๊ธฐ |
hf://yahma/alpaca-cleaned@~parquet/train | ์๋ Parquet ๋ณํ์ train ๋ถํ |
Zephon ๊ฒฝ๋ก์๋ ํ์ผ์ด ์๋ ๋ฐ์ดํฐ์ ๊ณผ ์คํ๋ฆฟ์ด ์ง์ ๋ฉ๋๋ค. pandas, Polars, DuckDB์์ ์ฌ์ฉํ๋
hf://datasets/...ํ์ผ ๊ฒฝ๋ก๋ฅผ ์ฌ์ฉํ์ง ์์ต๋๋ค.hf://datasets/HuggingFaceFW/fineweb-edu/sample-10BT/train๊ฐ ์๋hf://HuggingFaceFW/fineweb-edu/sample-10BT/train๋ฅผ ์ฌ์ฉํ์ธ์.
๋ฐ์ดํฐ์ ํผํฉ
์ฌ๋ฌ Hub ๋ฐ์ดํฐ์ ์ผ๋ก ํ์ตํ๋ ค๋ฉด, ๊ฐ ๋ฐ์ดํฐ์ ์ ๋น์จ์ ์ง์ ํ์ฌ ์ํฌ ์์ค์ ์ถ๊ฐํฉ๋๋ค. ์ด ์์์์๋ FineWeb-Edu์ ์์ด ์ํค๋ฐฑ๊ณผ๋ฅผ ํ ํฐ ๊ธฐ์ค 70/30 ๋น์จ๋ก ํผํฉํฉ๋๋ค:
from zephon import Pipeline
from zephon.io import CacheOptions, Dataset, StoreOptions
from zephon.work import MixtureSpec, StaticMixtureWorkSource, TokenEstimation
work_source = StaticMixtureWorkSource(
datasets=[
Dataset.from_path("fineweb_edu", "hf://HuggingFaceFW/fineweb-edu/sample-10BT/train"),
Dataset.from_path("wikipedia", "hf://wikimedia/wikipedia/20231101.en/train"),
],
mixture=MixtureSpec({"fineweb_edu": 0.7, "wikipedia": 0.3}),
seed=42,
token_estimation=TokenEstimation(primer="measure", calibration_samples=2048, calibration_shards_max=4),
)
cache = CacheOptions(enabled=True, root="/tmp/zephon-cache", limit_bytes=50 << 30) # 50 GiB
pipeline = (
Pipeline(work_source)
.options(io_options=StoreOptions(cache=cache))
.tokenize(tokenizer_id="gpt2", field="text")
.pack_flat(max_length=2049, algorithm="wrap")
.batch(microbatch_size=8)
)์ํ ๋จ์๋ก ํผํฉํ๋ ค๋ฉด token_estimation์ ์๋ตํ์ธ์.