Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.direnv
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.direnv/
.pre-commit-config.yaml
MODULE.bazel.lock
bazel-*
compile_commands.json
lre.bazelrc
35 changes: 35 additions & 0 deletions finetuning_on_cpu/.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Pick up system specific configs.
common --enable_platform_specific_config

# Don't inherit PATH and LD_LIBRARY_PATH.
build --incompatible_strict_action_env

# Forbid network access unless explicitly enabled.
build --sandbox_default_allow_network=false

# Use correct runfile locations.
build --nolegacy_external_runfiles

# Enable sandboxing for exclusive tests like GPU performance tests.
test --incompatible_exclusive_test_sandboxed

# Simulate rules_python's initialization with a script and use a statically
# linked musl Python toolchain.
common --@rules_python//python/config_settings:bootstrap_impl=script
common --@rules_python//python/config_settings:py_linux_libc=musl
# common --@rules_python//python/config_settings:pip_whl_muslc_version=3.13

# Remote optimizations.
build --remote_download_minimal

# Smaller profiling. Careful. Disabling this might explode remote cache usage.
build --slim_profile
build --experimental_profile_include_target_label
build --noexperimental_profile_include_primary_output

# Use the container image specified in `platforms/BUILD.bazel`.
build --extra_execution_platforms=@//platforms:python-remote
build --extra_toolchains=@zig_sdk//toolchain:linux_amd64_musl

# Add user specific flags.
try-import %workspace%/user.bazelrc
1 change: 1 addition & 0 deletions finetuning_on_cpu/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.2.1
6 changes: 6 additions & 0 deletions finetuning_on_cpu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store # only for macs
bazel-finetune-repo
bazel-out
bazel-bin
bazel-testlogs
.env
4 changes: 4 additions & 0 deletions finetuning_on_cpu/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
exports_files(
["python_provider.sh"],
visibility = ["//visibility:public"], # Makes it visible to all packages
)
22 changes: 22 additions & 0 deletions finetuning_on_cpu/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
bazel_dep(name = "hermetic_cc_toolchain", version = "4.0.0")
bazel_dep(name = "platforms", version = "0.0.11")
bazel_dep(name = "rules_cc", version = "0.1.1")
bazel_dep(name = "rules_python", version = "1.2.0")
bazel_dep(name = "rules_shell", version = "0.4.1")

# Used internally by rules_python.
cc_toolchains = use_extension("@hermetic_cc_toolchain//toolchain:ext.bzl", "toolchains")
use_repo(cc_toolchains, "zig_sdk")

# Python configuration
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
python.toolchain(python_version = "3.13")

# Python packages
pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
pip.parse(
hub_name = "pypi",
python_version = "3.13",
requirements_lock = "//:bazel_requirements_lock.txt",
)
use_repo(pip, "pypi")
3,776 changes: 3,776 additions & 0 deletions finetuning_on_cpu/MODULE.bazel.lock

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions finetuning_on_cpu/bazel_requirements_lock.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@

aiohappyeyeballs==2.6.1
# via aiohttp
aiohttp==3.11.14
# via
# datasets
# fsspec
aiosignal==1.3.2
# via aiohttp
async-timeout==5.0.1
# via aiohttp
attrs==25.3.0
# via aiohttp
certifi==2025.1.31
# via requests
charset-normalizer==3.4.1
# via requests
datasets==3.4.1
# via -r requirements.txt
dill==0.3.7
# via
# datasets
# multiprocess
filelock==3.18.0
# via
# huggingface-hub
# torch
# transformers
frozenlist==1.5.0
# via
# aiohttp
# aiosignal
fsspec[http]==2024.12.0
# via
# datasets
# huggingface-hub
# torch
huggingface-hub==0.29.3
# via
# datasets
# tokenizers
# transformers
idna==3.10
# via
# requests
# yarl
jinja2==3.1.6
# via torch
markupsafe==3.0.2
# via jinja2
mpmath==1.3.0
# via sympy
multidict==6.2.0
# via
# aiohttp
# yarl
multiprocess==0.70.15
# via datasets
networkx==3.2.1
# via torch
numpy==1.26.4
# via
# datasets
# pandas
# transformers
packaging==24.2
# via
# datasets
# huggingface-hub
# transformers
pandas==2.2.3
# via datasets
propcache==0.3.0
# via
# aiohttp
# yarl
pyarrow==19.0.1
# via datasets
python-dateutil==2.9.0.post0
# via pandas
pytz==2025.2
# via pandas
pyyaml==6.0.2
# via
# datasets
# huggingface-hub
# transformers
regex==2024.11.6
# via transformers
requests==2.32.3
# via
# datasets
# huggingface-hub
# transformers
safetensors==0.5.3
# via transformers
six==1.17.0
# via python-dateutil
sympy==1.13.1
# via torch
tokenizers==0.21.1
# via transformers
setuptools==69.0.2
# via torch
torch==2.6.0
# via -r requirements.txt
tqdm==4.67.1
# via
# datasets
# huggingface-hub
# transformers
transformers==4.50.1
# via -r requirements.txt
typing-extensions==4.12.2
# via
# huggingface-hub
# multidict
# torch
tzdata==2025.2
# via pandas
urllib3==2.3.0
# via requests
xxhash==3.5.0
# via datasets
yarl==1.18.3
# via aiohttp
accelerate==1.5.2
psutil==5.9.8
# for accelerate
anyio==4.9.0
# for transformers
distro==1.9.0
# for transformers
httpx==0.28.1
# for transformers
jiter==0.9.0
# for transformers
pydantic-core==2.33.0
# for transformers
pydantic==2.11.0
# for transformers
sniffio==1.3.1
# for httpx
httpcore==1.0.7
# for httpx
h11==0.14.0
# for httpx
annotated-types==0.7.0
# for transformers
typing-inspection==0.4.0
# for transformers
exceptiongroup==1.2.2
# for transformers
python-dotenv==1.1.0
# for loading env variables
scipy==1.15.2
# for torch to get embeddings

# Manual adjusted below.
nvidia-cublas-cu12==12.9.0.13
nvidia-cuda-cupti-cu12==12.9.19
nvidia-cuda-nvrtc-cu12==12.9.41
nvidia-cuda-runtime-cu12==12.9.37
nvidia-cudnn-cu12==9.10.0.56
nvidia-cufft-cu12==11.4.0.6
nvidia-curand-cu12==10.3.10.19
nvidia-cusolver-cu12==11.7.4.40
nvidia-cusparse-cu12==12.5.9.5
nvidia-cusparselt-cu12==0.7.1
nvidia-nccl-cu12==2.26.5
nvidia-nvjitlink-cu12==12.9.41
nvidia-nvtx-cu12==12.9.19
triton==3.3.0
12 changes: 12 additions & 0 deletions finetuning_on_cpu/platforms/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
platform(
name = "python-remote",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
exec_properties = {
"OSFamily": "Linux",
"ISA": "x86-64",
"container-image": "docker.io/evaanahmed2001/python-bazel-env@sha256:8de13199d587964b218c0b671272b42031cf4944b2f426e6eee7d7542802bf7c",
},
)
30 changes: 30 additions & 0 deletions finetuning_on_cpu/python_provider.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
# Generic Python test wrapper that handles cross-architecture execution

# Get the directory where this script is located
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# First argument is the Python module or script to run
PYTHON_SCRIPT="$1"
# Remaining arguments are passed to the Python script
shift

echo "Running Python test: $PYTHON_SCRIPT"
echo "Python version:"
python3 --version

# Check if the argument is a file or a module
if [[ -f "$PYTHON_SCRIPT" ]]; then
# Run as a script if it's a file
echo "Running as script"
python3 "$PYTHON_SCRIPT" "$@"
else
# Run as a module if it's not a file
echo "Running as module"
python3 -m "$PYTHON_SCRIPT" "$@"
fi

# Capture and return the exit code
exit_code=$?
echo "Python test completed with exit code: $exit_code"
exit $exit_code
27 changes: 27 additions & 0 deletions finetuning_on_cpu/src/training/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@rules_python//python:defs.bzl", "py_test")

exports_files(
["train_model.py"],
visibility = ["//visibility:public"], # Makes it visible to all packages
)

py_test(
name = "training_test",
size = "large",
srcs = ["train_model.py"],
main = "train_model.py",
# IMPORTANT: Model training is irreproducible. We can use NativeLink to
# speed up the build, but we can't "reuse" a cached model as
# every training run will yield different results. The `no-cache`
# flag here prevents any sort of caching while still allowing for
# remote execution in Nativelink's distributed infrastructure.
tags = ["no-cache"],
visibility = ["//visibility:public"],
deps = [
"@pypi//accelerate",
"@pypi//datasets",
"@pypi//psutil",
"@pypi//torch",
"@pypi//transformers",
],
)
Loading