p-doom/crowd-code-dataset-0.2 huggingface dataset:
[content] crowd-pilot/serialize_dataset_parquet.py (python)
from datasets import Dataset, load_dataset  # type: ignore



@dataclass
class SerializeConfig:
    output_dir: str
    shard_size: int
    target_chars: int
    overlap_chars: int
    min_session_chars: int
    max_docs: Optional[int]
    long_pause_threshold_ms: int
    csv_root: Optional[str]
    val_ratio: float
[content] crowd-pilot/serialize_dataset_parquet.py (python)
try:
    from .serialize_common import (
        SerializeConfig,
        _session_to_transcript,
        _discover_local_sessions,
        _chunk_text,
    )
except Exception:  # pragma: no cover
    from serialize_common import (
        SerializeConfig,
        _session_to_transcript,
        _discover_local_sessions,
        _chunk_text,
    )
[content] crowd-pilot/serialize_dataset_array_record.py (python)
@dataclass
class SerializeConfig:
    output_dir: str
    shard_size: int
    target_chars: int
    overlap_chars: int
    min_session_chars: int
    max_docs: Optional[int]
    long_pause_threshold_ms: int
    csv_root: Optional[str]
    val_ratio: float
[content] crowd-pilot/serialize_dataset_parquet.py (python)
 


def load_hf_csv(hf_path: str, split: str) -> Dataset:
    loaded = load_dataset(hf_path, split=split)

    assert isinstance(loaded, Dataset), "Expected a Dataset from load_dataset"
    return loaded


def _discover_local_sessions(root: Path) -> List[Path]:
    # Recursively find all CSV files
    paths: List[Path] = []
    for p in root.rglob("*.csv"):
        if p.is_file():
            paths.append(p)
    paths.sort()
    return paths


def _chunk_text(text: str, target_chars: int, overlap_chars: int) -> List[str]:
    """Split a long text into overlapping chunks near target length."""
    if target_chars <= 0:
        return [text]
    n = len(text)
    if n <= target_chars:
        return [text]

    chunks: List[str] = []
    start = 0
    # Ensure sane overlap
    overlap = max(0, min(overlap_chars, target_chars // 2))
    while start < n:
        end_target = min(start + target_chars, n)
        if end_target < n:
            end = end_target
        else:
            end = n
        chunk = text[start:end].strip()
        chunks.append(chunk)
        if end == n:
            break
        # advance with overlap
        start = max(0, end - overlap)
        if start >= n:
            break
    return chunks
[content] crowd-pilot/serialize_dataset_array_record.py (python)
        min_session_chars=args.min_session_chars,
        max_docs=args.max_docs,
        long_pause_threshold_ms=args.long_pause_threshold_ms,
        csv_root=(args.csv_root if args.csv_root else None),
        val_ratio=args.val_ratio,
    )


def main() -> None:
    cfg = parse_args()
    to_array_record(cfg)
[content] crowd-pilot/serialize_dataset_array_record.py (python)
def _discover_local_sessions(root: Path) -> List[Path]:
    # Recursively find all CSV files
    paths: List[Path] = []
    for p in root.rglob("*.csv"):
        if p.is_file():
            paths.append(p)
    paths.sort()
    return paths


def _chunk_text(text: str, target_chars: int, overlap_chars: int) -> List[str]:
    """Split a long text into overlapping chunks near target length."""
    if target_chars <= 0:
        return [text]
    n = len(text)
    if n <= target_chars:
        return [text]

    chunks: List[str] = []
    start = 0
    # Ensure sane overlap
    overlap = max(0, min(overlap_chars, target_chars // 2))
    while start < n:
        end_target = min(start + target_chars, n)
        if end_target < n:
            end = end_target
        else:
            end = n
        chunk = text[start:end].strip()
        chunks.append(chunk)
        if end == n:
            break
        # advance with overlap
        start = max(0, end - overlap)
        if start >= n:
            break
    return chunks
[content] crowd-pilot/serialize_dataset_array_record.py (python)
        min_session_chars=args.min_session_chars,
        max_docs=args.max_docs,
        long_pause_threshold_ms=args.long_pause_threshold_ms,
        csv_root=(args.csv_root if args.csv_root else None),
        val_ratio=args.val_ratio,
        arrayrecord_group_size=args.arrayrecord_group_size,
    )


def main() -> None:
    cfg = parse_args()
    to_array_record(cfg)
[content] crowd-pilot/serialize_dataset_array_record.py (python)
        min_session_chars=args.min_session_chars,
        max_docs=args.max_docs,
        long_pause_threshold_ms=args.long_pause_threshold_ms,
        csv_root=(args.csv_root if args.csv_root else None),
        val_ratio=args.val_ratio,
        arrayrecord_group_size=args.arrayrecord_group_size,
    )
[tab] slurm/dev/franz/berlin/crowd-pilot/generate_parquet_dataset.sh (shellscript)
#!/bin/bash

set -uex

OUTPUT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/"
CSV_ROOT="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/csv/"

uv run crowd-pilot/serialize_dataset.py --csv_root=$CSV_ROOT --output_dir=$OUTPUT_DIR
[content] slurm/dev/franz/berlin/crowd-pilot/generate_array_record_dataset.sh (shellscript)
#!/bin/bash

set -uex

OUTPUT_DIR="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/"
CSV_ROOT="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/csv/"

uv run crowd-pilot/serialize_dataset.py --csv_root=$CSV_ROOT --output_dir=$OUTPUT_DIR
[tab] slurm/dev/franz/berlin/crowd-pilot/train_maxtext.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --job-name=crowd-pilot_maxtext_dev
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# Log the sbatch script
cat $0

cd maxtext
source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID
BASE_OUTPUT_DIRECTORY=/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/outputs/
GRAIN_TRAIN_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/train_*.parquet"
GRAIN_EVAL_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/val_*.parquet"

env | grep SLURM

python3 -m MaxText.train \
  MaxText/configs/base.yml \
  run_name=${job_name}_${slurm_job_id} \
  base_output_directory=$BASE_OUTPUT_DIRECTORY \
  dataset_type=grain \
  grain_file_type=parquet \
  grain_train_files=$GRAIN_TRAIN_FILES \
  grain_eval_files=$GRAIN_EVAL_FILES \
  eval_interval=500 \
  steps=50000 \
  skip_jax_distributed_system=True
[content] slurm/dev/franz/berlin/crowd-pilot/train_maxtext_array_record.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --job-name=crowd-pilot_maxtext_dev
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# Log the sbatch script
cat $0

cd maxtext
source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID
BASE_OUTPUT_DIRECTORY=/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/outputs/
GRAIN_TRAIN_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/train_*.parquet"
GRAIN_EVAL_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/val_*.parquet"

env | grep SLURM

python3 -m MaxText.train \
  MaxText/configs/base.yml \
  run_name=${job_name}_${slurm_job_id} \
  base_output_directory=$BASE_OUTPUT_DIRECTORY \
  dataset_type=grain \
  grain_file_type=parquet \
  grain_train_files=$GRAIN_TRAIN_FILES \
  grain_eval_files=$GRAIN_EVAL_FILES \
  eval_interval=500 \
  steps=50000 \
  skip_jax_distributed_system=True
[content] slurm/dev/franz/berlin/crowd-pilot/train_maxtext_array_record_10_epochs.sh (shellscript)
#!/usr/bin/env bash

#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --gres=gpu:1
#SBATCH --time=24:00:00
#SBATCH --cpus-per-task=8
#SBATCH --output=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --error=/fast/project/HFMI_SynergyUnit/jafar_ws/logs/franz/crowd-pilot/maxtext/%x_%j.log
#SBATCH --job-name=crowd-pilot_maxtext_10_epochs
#SBATCH --requeue
#SBATCH --signal=b:usr1@300 # 5 min before timeout

# Log the sbatch script
cat $0

cd maxtext
source .venv/bin/activate

job_name=$SLURM_JOB_NAME
slurm_job_id=$SLURM_JOB_ID
BASE_OUTPUT_DIRECTORY=/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/outputs/
GRAIN_TRAIN_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/train_*.parquet"
GRAIN_EVAL_FILES="/fast/project/HFMI_SynergyUnit/jafar_ws/data/crowd-pilot/crowd-code-0.1/parquet/val_*.parquet"

env | grep SLURM

python3 -m MaxText.train \
  MaxText/configs/base.yml \
  run_name=${job_name}_${slurm_job_id} \
  base_output_directory=$BASE_OUTPUT_DIRECTORY \
  dataset_type=grain \
  grain_file_type=parquet \
  grain_train_files=$GRAIN_TRAIN_FILES \
  grain_eval_files=$GRAIN_EVAL_FILES \
  eval_interval=500 \
  steps=50000 \
  num_epoch=10 \
  skip_jax_distributed_system=True
[content] crowd-pilot/serialize_dataset_array_record.py (python)
                # MaxText expects ArrayRecord elements to be serialized tf.train.Example
                # with a feature named "text" (string list) when tokenize=True.
                example = tf.train.Example(
                    features=tf.train.Features(
                        feature={
                            "text": tf.train.Feature(
                                bytes_list=tf.train.BytesList(value=[chunk.encode("utf-8")])
                            )
                        }
                    )
                )
                writer.write(example.SerializeToString())