Skip to content

Commit 06fe896

Browse files
author
Haojin Yang
committed
Initial commit for BItorch Engine.
0 parents  commit 06fe896

File tree

168 files changed

+25481
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+25481
-0
lines changed

.dev-scripts/publish.sh

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#!/usr/bin/env bash
2+
3+
function usage() {
4+
echo "./.dev-scripts/publish.sh VERSION"
5+
echo "builds a package and publishes it to (test-)pypi"
6+
echo
7+
echo "VERSION must be either 'pre-release' or 'release'."
8+
}
9+
10+
if ! [ "$#" = "1" ] || [ "${1}" = "-h" ]; then
11+
usage
12+
exit
13+
fi
14+
15+
if ! [ "${1}" = "release" ] && ! [ "${1}" = "pre-release" ]; then
16+
usage
17+
exit
18+
fi
19+
20+
# set SCRIPT_ROOT:
21+
SCRIPT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
22+
23+
# set SRC_ROOT and make sure that is our working directory
24+
SRC_ROOT="$(readlink -f "${SCRIPT_ROOT}/..")"
25+
cd "${SRC_ROOT}"
26+
27+
trap exit INT
28+
29+
function check_yes() {
30+
# asks the given yes or no question, returns true if they answer YES
31+
# usage:
32+
# if check_yes "Do you really want to delete foo?"; then
33+
# rm foo
34+
# fi
35+
36+
local prompt="${1}"
37+
read -p "${prompt} [y/N] " REPLY
38+
echo ""
39+
if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then
40+
return 1
41+
fi
42+
return 0
43+
}
44+
45+
function check_no() {
46+
# asks the given yes or no question, returns false if they answer NO
47+
# usage:
48+
# if check_no "Do you want to exit the script?"; then
49+
# exit 0
50+
# fi
51+
52+
local prompt="${1}"
53+
read -p "${prompt} [Y/n] " REPLY
54+
echo ""
55+
if [[ "${REPLY}" =~ ^[Nn]$ ]]; then
56+
return 1
57+
fi
58+
return 0
59+
}
60+
61+
function check_error() {
62+
# shows and then runs a command. if the exit code is not zero, asks the user whether to continue
63+
# usage: check_error mv foo bar
64+
65+
echo + $@
66+
"$@"
67+
local exit_code=$?
68+
if [ "${exit_code}" -ne 0 ]; then
69+
if ! check_yes "! > An error occurred, continue with the script?"; then
70+
if [ "${1}" = "pre-release" ]; then
71+
git checkout "${version_file}"
72+
fi
73+
exit 1
74+
fi
75+
fi
76+
}
77+
78+
# main script content
79+
80+
if [ -z "$(git status --porcelain)" ]; then
81+
echo "Git seems clean."
82+
else
83+
echo "There are uncommitted changes, aborting."
84+
exit 1
85+
fi
86+
87+
if [ "${1}" = "release" ]; then
88+
version_file="${SRC_ROOT}/version.txt"
89+
version_content="$(cat "${version_file}")"
90+
major_minor_patch="$(cut -d '.' -f 1,2,3 <<< "${version_content}")"
91+
version_str="${major_minor_patch}"
92+
else
93+
version_file="${SRC_ROOT}/version.txt"
94+
version_content="$(cat "${version_file}")"
95+
major_minor_patch="$(cut -d '.' -f 1,2,3 <<< "${version_content}")"
96+
date_str="$(date +"%Y%m%d")"
97+
git_ref="$(git rev-parse --short HEAD)"
98+
version_str="${major_minor_patch}.dev${date_str}+${git_ref}"
99+
fi
100+
101+
if [ "${1}" = "release" ] && ! [ "${version_content}" = "${version_str}" ]; then
102+
echo "The file version.txt does not seem to contain a release version."
103+
exit 1
104+
else
105+
if ! check_no "Publish version ${version_str} ?"; then
106+
exit 0
107+
fi
108+
fi
109+
110+
if [ "${1}" = "pre-release" ]; then
111+
echo "${version_str}" > "${version_file}"
112+
fi
113+
114+
check_error pip uninstall -y -r <(pip freeze)
115+
check_error pip install --upgrade pip
116+
check_error pip install -e ".[dev]" -v
117+
118+
pip install build twine
119+
120+
check_error pytest .
121+
check_error python3 -m build --sdist
122+
123+
if check_yes "Publish to real PyPi?"; then
124+
echo "Do:"
125+
echo ' python3 -m twine dist/*'
126+
else
127+
echo "Do:"
128+
echo ' python3 -m twine upload --repository testpypi dist/*'
129+
fi
130+
131+
if [ "${1}" = "pre-release" ]; then
132+
git checkout "${version_file}"
133+
fi

.gitignore

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
README.rst
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
99+
__pypackages__/
100+
101+
# Celery stuff
102+
celerybeat-schedule
103+
celerybeat.pid
104+
105+
# SageMath parsed files
106+
*.sage.py
107+
108+
# Environments
109+
.env
110+
.venv
111+
env/
112+
venv/
113+
ENV/
114+
env.bak/
115+
venv.bak/
116+
117+
# Spyder project settings
118+
.spyderproject
119+
.spyproject
120+
121+
# Rope project settings
122+
.ropeproject
123+
124+
# mkdocs documentation
125+
/site
126+
127+
# mypy
128+
.mypy_cache/
129+
.dmypy.json
130+
dmypy.json
131+
132+
# Pyre type checker
133+
.pyre/
134+
135+
# pytype static type analyzer
136+
.pytype/
137+
138+
# Cython debug symbols
139+
cython_debug/
140+
141+
.coverage
142+
.idea/
143+
.vscode/
144+
.mypy_cache
145+
146+
# downloaded dataset files
147+
train/
148+
test/

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
5+
and this project adheres to [Semantic Versioning](http://semver.org/).
6+
7+
8+
## [0.2.0] - 2024/03/10
9+
10+
### Added
11+
12+
- Quantized layers with different acceleration options
13+
- QConv (binary, quantized) - CPU, Cutlass
14+
- QLinear (binary, quantized, mixed bit-width) - CUDA, Cutlass, MPS
15+
- QEmbedding (binary)
16+
- Optimizer(s) for quantized layers
17+
- Hybrid optimizer `diode_beta` based on Diode v1 (binary) and AdamW (quantized) for memory-efficient training
18+
- Initial support for galore projection
19+
- Examples
20+
- MNIST training script with and without PyTorch Lightning
21+
22+
## [0.1.0] - 2023/01/13
23+
24+
The first release of basic functionality.

CONTRIBUTING.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Contributing to Bitorch Engine
2+
Your contributions are welcomed and appreciated. We strive to make the process straightforward and transparent.
3+
4+
## Development
5+
1. Propose significant changes via an Request for Comments (RFC) for discussion.
6+
2. Add features by submitting a PR with accompanying tests and documentation.
7+
3. Fix bugs by submitting a PR that includes tests validating the fix and any necessary documentation updates.
8+
9+
## Pull Requests
10+
We encourage your pull requests.
11+
12+
1. Fork the repository and create your branch from main.
13+
2. Include tests for any new code.
14+
3. Update documentation for all related functions.
15+
4. Ensure all tests are passing.
16+
17+
## Reporting Issues
18+
We track bugs with GitHub issues. Provide a clear description and instructions to reproduce the issue.
19+
20+
## Your Contributions
21+
Contributions are **licensed under the LICENSE** file found in the root directory of this source tree.

0 commit comments

Comments
 (0)