smolbrain 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- smolbrain-0.1.0/.editorconfig +15 -0
- smolbrain-0.1.0/.github/pull_request_template.md +14 -0
- smolbrain-0.1.0/.github/workflows/ci.yml +43 -0
- smolbrain-0.1.0/.github/workflows/docs.yml +52 -0
- smolbrain-0.1.0/.github/workflows/publish.yml +48 -0
- smolbrain-0.1.0/.gitignore +33 -0
- smolbrain-0.1.0/.pre-commit-config.yaml +16 -0
- smolbrain-0.1.0/CHANGELOG.md +249 -0
- smolbrain-0.1.0/CONTRIBUTING.md +31 -0
- smolbrain-0.1.0/LICENSE +21 -0
- smolbrain-0.1.0/Makefile +46 -0
- smolbrain-0.1.0/PKG-INFO +100 -0
- smolbrain-0.1.0/README.md +68 -0
- smolbrain-0.1.0/benchmarks/README.md +6 -0
- smolbrain-0.1.0/docs/.vitepress/config.mts +166 -0
- smolbrain-0.1.0/docs/.vitepress/theme/custom.css +37 -0
- smolbrain-0.1.0/docs/.vitepress/theme/index.ts +4 -0
- smolbrain-0.1.0/docs/book/01-numbers.md +340 -0
- smolbrain-0.1.0/docs/book/02-neurons.md +295 -0
- smolbrain-0.1.0/docs/book/03-being-wrong-less.md +361 -0
- smolbrain-0.1.0/docs/book/04-building-a-brain.md +416 -0
- smolbrain-0.1.0/docs/book/05-data.md +357 -0
- smolbrain-0.1.0/docs/book/06-did-it-really-learn.md +407 -0
- smolbrain-0.1.0/docs/book/07-keeping-a-brain.md +337 -0
- smolbrain-0.1.0/docs/book/08-seeing-things.md +518 -0
- smolbrain-0.1.0/docs/book/09-doing-more-with-less.md +458 -0
- smolbrain-0.1.0/docs/book/10-paying-attention.md +426 -0
- smolbrain-0.1.0/docs/book/11-brains-that-write.md +404 -0
- smolbrain-0.1.0/docs/book/12-learning-a-bit-more.md +407 -0
- smolbrain-0.1.0/docs/book/13-in-french.md +356 -0
- smolbrain-0.1.0/docs/book/14-faster.md +311 -0
- smolbrain-0.1.0/docs/book/15-copying-itself.md +422 -0
- smolbrain-0.1.0/docs/book/16-who-knows-whom.md +275 -0
- smolbrain-0.1.0/docs/book/17-making-things-up.md +407 -0
- smolbrain-0.1.0/docs/book/index.md +98 -0
- smolbrain-0.1.0/docs/fr/index.md +32 -0
- smolbrain-0.1.0/docs/fr/livre/01-nombres.md +343 -0
- smolbrain-0.1.0/docs/fr/livre/02-neurones.md +295 -0
- smolbrain-0.1.0/docs/fr/livre/03-se-tromper-moins.md +363 -0
- smolbrain-0.1.0/docs/fr/livre/04-construire-un-cerveau.md +420 -0
- smolbrain-0.1.0/docs/fr/livre/05-donnees.md +357 -0
- smolbrain-0.1.0/docs/fr/livre/06-a-t-il-vraiment-appris.md +409 -0
- smolbrain-0.1.0/docs/fr/livre/07-garder-un-cerveau.md +339 -0
- smolbrain-0.1.0/docs/fr/livre/08-voir-des-choses.md +518 -0
- smolbrain-0.1.0/docs/fr/livre/09-faire-plus-avec-moins.md +458 -0
- smolbrain-0.1.0/docs/fr/livre/10-faire-attention.md +426 -0
- smolbrain-0.1.0/docs/fr/livre/11-des-cerveaux-qui-ecrivent.md +404 -0
- smolbrain-0.1.0/docs/fr/livre/12-apprendre-encore-un-peu.md +407 -0
- smolbrain-0.1.0/docs/fr/livre/13-en-francais.md +356 -0
- smolbrain-0.1.0/docs/fr/livre/14-plus-vite.md +311 -0
- smolbrain-0.1.0/docs/fr/livre/15-se-recopier.md +422 -0
- smolbrain-0.1.0/docs/fr/livre/16-qui-connait-qui.md +277 -0
- smolbrain-0.1.0/docs/fr/livre/17-inventer.md +407 -0
- smolbrain-0.1.0/docs/fr/livre/index.md +102 -0
- smolbrain-0.1.0/docs/fr/reference/dictionnaire.md +527 -0
- smolbrain-0.1.0/docs/index.md +32 -0
- smolbrain-0.1.0/docs/package-lock.json +2516 -0
- smolbrain-0.1.0/docs/package.json +13 -0
- smolbrain-0.1.0/docs/project/adr/0001-two-floor-api.md +24 -0
- smolbrain-0.1.0/docs/project/adr/0002-numpy-first-backend.md +19 -0
- smolbrain-0.1.0/docs/project/adr/0003-fun-names-with-serious-aliases.md +20 -0
- smolbrain-0.1.0/docs/project/adr/README.md +10 -0
- smolbrain-0.1.0/docs/project/architecture.md +61 -0
- smolbrain-0.1.0/docs/project/brand.md +20 -0
- smolbrain-0.1.0/docs/project/roadmap.md +39 -0
- smolbrain-0.1.0/docs/public/favicon.svg +1 -0
- smolbrain-0.1.0/docs/public/logo-wordmark-dark.svg +1 -0
- smolbrain-0.1.0/docs/public/logo-wordmark.svg +1 -0
- smolbrain-0.1.0/docs/public/logo.svg +1 -0
- smolbrain-0.1.0/docs/reference/dictionary.md +520 -0
- smolbrain-0.1.0/examples/README.md +12 -0
- smolbrain-0.1.0/pyproject.toml +121 -0
- smolbrain-0.1.0/src/smolbrain/__init__.py +400 -0
- smolbrain-0.1.0/src/smolbrain/_internal/__init__.py +1 -0
- smolbrain-0.1.0/src/smolbrain/_internal/aliasing.py +4 -0
- smolbrain-0.1.0/src/smolbrain/_internal/validation.py +3 -0
- smolbrain-0.1.0/src/smolbrain/_version.py +3 -0
- smolbrain-0.1.0/src/smolbrain/backend/__init__.py +98 -0
- smolbrain-0.1.0/src/smolbrain/backend/base.py +223 -0
- smolbrain-0.1.0/src/smolbrain/backend/kernels.c +111 -0
- smolbrain-0.1.0/src/smolbrain/backend/native.py +156 -0
- smolbrain-0.1.0/src/smolbrain/backend/numpy_backend.py +210 -0
- smolbrain-0.1.0/src/smolbrain/brain/__init__.py +51 -0
- smolbrain-0.1.0/src/smolbrain/brain/brain.py +972 -0
- smolbrain-0.1.0/src/smolbrain/brain/checking.py +484 -0
- smolbrain-0.1.0/src/smolbrain/brain/duel.py +192 -0
- smolbrain-0.1.0/src/smolbrain/brain/inputs.py +97 -0
- smolbrain-0.1.0/src/smolbrain/brain/keeping.py +680 -0
- smolbrain-0.1.0/src/smolbrain/brain/outputs.py +701 -0
- smolbrain-0.1.0/src/smolbrain/brain/resources.py +167 -0
- smolbrain-0.1.0/src/smolbrain/core/__init__.py +24 -0
- smolbrain-0.1.0/src/smolbrain/core/autograd.py +89 -0
- smolbrain-0.1.0/src/smolbrain/core/creation.py +74 -0
- smolbrain-0.1.0/src/smolbrain/core/dtypes.py +14 -0
- smolbrain-0.1.0/src/smolbrain/core/tensor.py +660 -0
- smolbrain-0.1.0/src/smolbrain/data/__init__.py +39 -0
- smolbrain-0.1.0/src/smolbrain/data/dataset.py +210 -0
- smolbrain-0.1.0/src/smolbrain/data/datasets/__init__.py +370 -0
- smolbrain-0.1.0/src/smolbrain/data/datasets/files/flowers.csv +151 -0
- smolbrain-0.1.0/src/smolbrain/data/datasets/registry.py +69 -0
- smolbrain-0.1.0/src/smolbrain/data/graph.py +170 -0
- smolbrain-0.1.0/src/smolbrain/data/images.py +255 -0
- smolbrain-0.1.0/src/smolbrain/data/loaders.py +275 -0
- smolbrain-0.1.0/src/smolbrain/data/peek.py +131 -0
- smolbrain-0.1.0/src/smolbrain/data/text.py +218 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/__init__.py +23 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/accumulation.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/budget.py +143 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/checkpointing.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/distillation.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/lazy.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/precision.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/pruning.py +1 -0
- smolbrain-0.1.0/src/smolbrain/efficiency/quantization.py +230 -0
- smolbrain-0.1.0/src/smolbrain/errors.py +152 -0
- smolbrain-0.1.0/src/smolbrain/fr/__init__.py +159 -0
- smolbrain-0.1.0/src/smolbrain/fr/datasets.py +25 -0
- smolbrain-0.1.0/src/smolbrain/fr/errors.py +141 -0
- smolbrain-0.1.0/src/smolbrain/fr/names.py +334 -0
- smolbrain-0.1.0/src/smolbrain/fr/translation.py +226 -0
- smolbrain-0.1.0/src/smolbrain/hardware/__init__.py +5 -0
- smolbrain-0.1.0/src/smolbrain/hardware/devices.py +1 -0
- smolbrain-0.1.0/src/smolbrain/hardware/system.py +138 -0
- smolbrain-0.1.0/src/smolbrain/layers/__init__.py +145 -0
- smolbrain-0.1.0/src/smolbrain/layers/activations.py +101 -0
- smolbrain-0.1.0/src/smolbrain/layers/attention.py +367 -0
- smolbrain-0.1.0/src/smolbrain/layers/augment.py +163 -0
- smolbrain-0.1.0/src/smolbrain/layers/base.py +253 -0
- smolbrain-0.1.0/src/smolbrain/layers/conv.py +172 -0
- smolbrain-0.1.0/src/smolbrain/layers/dense.py +116 -0
- smolbrain-0.1.0/src/smolbrain/layers/embedding.py +148 -0
- smolbrain-0.1.0/src/smolbrain/layers/fuzzy.py +84 -0
- smolbrain-0.1.0/src/smolbrain/layers/graph.py +102 -0
- smolbrain-0.1.0/src/smolbrain/layers/little_change.py +40 -0
- smolbrain-0.1.0/src/smolbrain/layers/normalization.py +79 -0
- smolbrain-0.1.0/src/smolbrain/layers/pooling.py +118 -0
- smolbrain-0.1.0/src/smolbrain/layers/recurrent.py +147 -0
- smolbrain-0.1.0/src/smolbrain/layers/scaling.py +80 -0
- smolbrain-0.1.0/src/smolbrain/layers/structural.py +121 -0
- smolbrain-0.1.0/src/smolbrain/layers/transformer.py +183 -0
- smolbrain-0.1.0/src/smolbrain/llm/__init__.py +25 -0
- smolbrain-0.1.0/src/smolbrain/llm/blabber.py +746 -0
- smolbrain-0.1.0/src/smolbrain/llm/chat.py +157 -0
- smolbrain-0.1.0/src/smolbrain/llm/generation.py +207 -0
- smolbrain-0.1.0/src/smolbrain/llm/lora.py +110 -0
- smolbrain-0.1.0/src/smolbrain/llm/summon.py +266 -0
- smolbrain-0.1.0/src/smolbrain/llm/tokenizer.py +348 -0
- smolbrain-0.1.0/src/smolbrain/observe/__init__.py +20 -0
- smolbrain-0.1.0/src/smolbrain/observe/explain.py +37 -0
- smolbrain-0.1.0/src/smolbrain/observe/metrics.py +174 -0
- smolbrain-0.1.0/src/smolbrain/observe/plots.py +100 -0
- smolbrain-0.1.0/src/smolbrain/observe/saliency.py +60 -0
- smolbrain-0.1.0/src/smolbrain/py.typed +0 -0
- smolbrain-0.1.0/src/smolbrain/storage/__init__.py +9 -0
- smolbrain-0.1.0/src/smolbrain/storage/export.py +1 -0
- smolbrain-0.1.0/src/smolbrain/storage/serialization.py +193 -0
- smolbrain-0.1.0/src/smolbrain/training/__init__.py +35 -0
- smolbrain-0.1.0/src/smolbrain/training/callbacks.py +40 -0
- smolbrain-0.1.0/src/smolbrain/training/history.py +46 -0
- smolbrain-0.1.0/src/smolbrain/training/losses.py +179 -0
- smolbrain-0.1.0/src/smolbrain/training/optimizers.py +206 -0
- smolbrain-0.1.0/src/smolbrain/training/schedulers.py +18 -0
- smolbrain-0.1.0/src/smolbrain/training/trainer.py +314 -0
- smolbrain-0.1.0/tests/conftest.py +1 -0
- smolbrain-0.1.0/tests/integration/.gitkeep +0 -0
- smolbrain-0.1.0/tests/unit/backend/test_native.py +180 -0
- smolbrain-0.1.0/tests/unit/backend/test_numpy_backend.py +87 -0
- smolbrain-0.1.0/tests/unit/brain/test_brain.py +340 -0
- smolbrain-0.1.0/tests/unit/brain/test_brain_data.py +115 -0
- smolbrain-0.1.0/tests/unit/brain/test_checking.py +275 -0
- smolbrain-0.1.0/tests/unit/brain/test_graphs.py +107 -0
- smolbrain-0.1.0/tests/unit/brain/test_inputs_outputs.py +188 -0
- smolbrain-0.1.0/tests/unit/brain/test_inventing.py +147 -0
- smolbrain-0.1.0/tests/unit/brain/test_itself.py +186 -0
- smolbrain-0.1.0/tests/unit/brain/test_keeping.py +233 -0
- smolbrain-0.1.0/tests/unit/brain/test_reading_brain.py +134 -0
- smolbrain-0.1.0/tests/unit/brain/test_resources.py +152 -0
- smolbrain-0.1.0/tests/unit/brain/test_seeing_brain.py +141 -0
- smolbrain-0.1.0/tests/unit/core/test_aliases.py +33 -0
- smolbrain-0.1.0/tests/unit/core/test_autograd.py +206 -0
- smolbrain-0.1.0/tests/unit/core/test_tensor.py +165 -0
- smolbrain-0.1.0/tests/unit/data/test_builtin_datasets.py +101 -0
- smolbrain-0.1.0/tests/unit/data/test_dataset.py +105 -0
- smolbrain-0.1.0/tests/unit/data/test_from_folder.py +300 -0
- smolbrain-0.1.0/tests/unit/data/test_peek_and_csv.py +83 -0
- smolbrain-0.1.0/tests/unit/data/test_sentences.py +88 -0
- smolbrain-0.1.0/tests/unit/data/test_text.py +68 -0
- smolbrain-0.1.0/tests/unit/efficiency/test_budget.py +93 -0
- smolbrain-0.1.0/tests/unit/efficiency/test_squeeze.py +57 -0
- smolbrain-0.1.0/tests/unit/fr/test_french.py +287 -0
- smolbrain-0.1.0/tests/unit/hardware/test_system.py +69 -0
- smolbrain-0.1.0/tests/unit/layers/test_activations.py +72 -0
- smolbrain-0.1.0/tests/unit/layers/test_layers.py +266 -0
- smolbrain-0.1.0/tests/unit/layers/test_modern.py +178 -0
- smolbrain-0.1.0/tests/unit/layers/test_seeing.py +281 -0
- smolbrain-0.1.0/tests/unit/layers/test_words.py +256 -0
- smolbrain-0.1.0/tests/unit/llm/__init__.py +1 -0
- smolbrain-0.1.0/tests/unit/llm/test_blabber.py +194 -0
- smolbrain-0.1.0/tests/unit/llm/test_chopper.py +69 -0
- smolbrain-0.1.0/tests/unit/llm/test_lora.py +184 -0
- smolbrain-0.1.0/tests/unit/llm/test_summon.py +158 -0
- smolbrain-0.1.0/tests/unit/llm/test_talk.py +128 -0
- smolbrain-0.1.0/tests/unit/llm/tiny_llama.py +157 -0
- smolbrain-0.1.0/tests/unit/observe/test_observe.py +164 -0
- smolbrain-0.1.0/tests/unit/storage/test_serialization.py +101 -0
- smolbrain-0.1.0/tests/unit/test_errors.py +81 -0
- smolbrain-0.1.0/tests/unit/test_package.py +20 -0
- smolbrain-0.1.0/tests/unit/training/test_losses.py +93 -0
- smolbrain-0.1.0/tests/unit/training/test_optimizers.py +80 -0
- smolbrain-0.1.0/tests/unit/training/test_trainer.py +203 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
## What
|
|
2
|
+
|
|
3
|
+
<!-- One or two sentences. -->
|
|
4
|
+
|
|
5
|
+
## Why
|
|
6
|
+
|
|
7
|
+
<!-- The problem this solves. -->
|
|
8
|
+
|
|
9
|
+
## Checklist
|
|
10
|
+
|
|
11
|
+
- [ ] `make check` passes
|
|
12
|
+
- [ ] New public names are in `docs/reference/dictionary.md` and `docs/fr/reference/dictionnaire.md`
|
|
13
|
+
- [ ] Errors use `smolbrain.errors` with a `try_this` hint
|
|
14
|
+
- [ ] `CHANGELOG.md` updated
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
quality:
|
|
14
|
+
name: Lint, types, architecture
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v4
|
|
18
|
+
- uses: actions/setup-python@v5
|
|
19
|
+
with:
|
|
20
|
+
python-version: "3.12"
|
|
21
|
+
cache: pip
|
|
22
|
+
- run: pip install -e ".[dev]"
|
|
23
|
+
- run: ruff format --check src tests
|
|
24
|
+
- run: ruff check src tests
|
|
25
|
+
- run: mypy
|
|
26
|
+
- run: lint-imports
|
|
27
|
+
|
|
28
|
+
test:
|
|
29
|
+
name: Tests (Python ${{ matrix.python }}, ${{ matrix.os }})
|
|
30
|
+
runs-on: ${{ matrix.os }}
|
|
31
|
+
strategy:
|
|
32
|
+
fail-fast: false
|
|
33
|
+
matrix:
|
|
34
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
35
|
+
python: ["3.10", "3.11", "3.12", "3.13"]
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: actions/setup-python@v5
|
|
39
|
+
with:
|
|
40
|
+
python-version: ${{ matrix.python }}
|
|
41
|
+
cache: pip
|
|
42
|
+
- run: pip install -e ".[dev]"
|
|
43
|
+
- run: pytest --cov --cov-report=term-missing
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
paths: ["docs/**", ".github/workflows/docs.yml"]
|
|
7
|
+
pull_request:
|
|
8
|
+
paths: ["docs/**", ".github/workflows/docs.yml"]
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
pages: write
|
|
14
|
+
id-token: write
|
|
15
|
+
|
|
16
|
+
concurrency:
|
|
17
|
+
group: pages-${{ github.ref }}
|
|
18
|
+
cancel-in-progress: true
|
|
19
|
+
|
|
20
|
+
jobs:
|
|
21
|
+
build:
|
|
22
|
+
name: Build the book
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
defaults:
|
|
25
|
+
run:
|
|
26
|
+
working-directory: docs
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v4
|
|
29
|
+
with:
|
|
30
|
+
fetch-depth: 0 # "last updated" dates come from git history
|
|
31
|
+
- uses: actions/setup-node@v4
|
|
32
|
+
with:
|
|
33
|
+
node-version: 22
|
|
34
|
+
cache: npm
|
|
35
|
+
cache-dependency-path: docs/package-lock.json
|
|
36
|
+
- run: npm ci
|
|
37
|
+
- run: npm run build
|
|
38
|
+
- uses: actions/upload-pages-artifact@v3
|
|
39
|
+
with:
|
|
40
|
+
path: docs/.vitepress/dist
|
|
41
|
+
|
|
42
|
+
deploy:
|
|
43
|
+
name: Publish to GitHub Pages
|
|
44
|
+
if: github.event_name != 'pull_request'
|
|
45
|
+
needs: build
|
|
46
|
+
runs-on: ubuntu-latest
|
|
47
|
+
environment:
|
|
48
|
+
name: github-pages
|
|
49
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
50
|
+
steps:
|
|
51
|
+
- id: deployment
|
|
52
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
name: Publish
|
|
2
|
+
|
|
3
|
+
# Publishes to PyPI when a GitHub release is published (tag vX.Y.Z).
|
|
4
|
+
# No token: PyPI trusts this workflow (Trusted Publishing, environment "pypi").
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [published]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build the package
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
- name: Check that the tag matches the version
|
|
20
|
+
run: |
|
|
21
|
+
version=$(python -c "exec(open('src/smolbrain/_version.py').read()); print(__version__)")
|
|
22
|
+
if [ "${GITHUB_REF_NAME}" != "v${version}" ]; then
|
|
23
|
+
echo "the tag is ${GITHUB_REF_NAME}, but src/smolbrain/_version.py says ${version}"
|
|
24
|
+
exit 1
|
|
25
|
+
fi
|
|
26
|
+
- run: pip install build twine
|
|
27
|
+
- run: python -m build
|
|
28
|
+
- run: twine check --strict dist/*
|
|
29
|
+
- uses: actions/upload-artifact@v4
|
|
30
|
+
with:
|
|
31
|
+
name: dist
|
|
32
|
+
path: dist/
|
|
33
|
+
|
|
34
|
+
publish:
|
|
35
|
+
name: Publish to PyPI
|
|
36
|
+
needs: build
|
|
37
|
+
runs-on: ubuntu-latest
|
|
38
|
+
environment:
|
|
39
|
+
name: pypi
|
|
40
|
+
url: https://pypi.org/project/smolbrain/
|
|
41
|
+
permissions:
|
|
42
|
+
id-token: write
|
|
43
|
+
steps:
|
|
44
|
+
- uses: actions/download-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: dist
|
|
47
|
+
path: dist/
|
|
48
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.egg-info/
|
|
5
|
+
build/
|
|
6
|
+
dist/
|
|
7
|
+
|
|
8
|
+
# Environments
|
|
9
|
+
.venv/
|
|
10
|
+
.env
|
|
11
|
+
|
|
12
|
+
# Tooling
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.mypy_cache/
|
|
15
|
+
.ruff_cache/
|
|
16
|
+
.import_linter_cache/
|
|
17
|
+
.coverage
|
|
18
|
+
coverage.xml
|
|
19
|
+
htmlcov/
|
|
20
|
+
|
|
21
|
+
# smolbrain
|
|
22
|
+
*.smol
|
|
23
|
+
.smolbrain_cache/
|
|
24
|
+
|
|
25
|
+
# OS / editors
|
|
26
|
+
.DS_Store
|
|
27
|
+
.idea/
|
|
28
|
+
.vscode/
|
|
29
|
+
|
|
30
|
+
# Docs site
|
|
31
|
+
docs/node_modules/
|
|
32
|
+
docs/.vitepress/dist/
|
|
33
|
+
docs/.vitepress/cache/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v5.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: trailing-whitespace
|
|
6
|
+
- id: end-of-file-fixer
|
|
7
|
+
- id: check-yaml
|
|
8
|
+
- id: check-toml
|
|
9
|
+
- id: check-added-large-files
|
|
10
|
+
|
|
11
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
12
|
+
rev: v0.17.6
|
|
13
|
+
hooks:
|
|
14
|
+
- id: ruff-format
|
|
15
|
+
- id: ruff
|
|
16
|
+
args: [--fix]
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here.
|
|
4
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
|
+
and the project uses [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-12-05
|
|
10
|
+
|
|
11
|
+
First release on PyPI: `pip install smolbrain`. The book is complete (chapters 1 to 17).
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- Chapter 17, "Making things up": `sb.less_noise(steps=100)` (also `diffusion`) is an
|
|
16
|
+
answer for brains that learn to take noise away. While learning, each picture gets a
|
|
17
|
+
random amount of noise, and its level as one more row of pixels; the brain answers the
|
|
18
|
+
clean picture. `bro.dream(count)` then starts from pure noise and cleans it `steps`
|
|
19
|
+
times; `bro.dream(count, every=25)` also gives the pictures along the way.
|
|
20
|
+
`sb.forger_and_detective(forger, detective, ideas=16, step=0.0002)` (also `GAN`) makes
|
|
21
|
+
two brains learn against each other: `duel.be_wrong_less(data)`, then `duel.dream(8)`.
|
|
22
|
+
The detective learns to say "real" at 90% at most. French: `sb.moins_de_bruit`,
|
|
23
|
+
`sb.faussaire_et_detective`, `cerveau.rever(4, tous_les=25)`.
|
|
24
|
+
|
|
25
|
+
- Chapter 16, "Who knows whom": `sb.from_graph(points, links, answers)` makes a dataset
|
|
26
|
+
of a graph (`GraphData`); `None` marks the answers nobody knows, and `split` hides
|
|
27
|
+
answers without cutting the graph. `sb.ask_the_neighbors(count)` (also `GCNConv`,
|
|
28
|
+
`GraphConv`) averages each point with its neighbors, then thinks with neurons. A graph
|
|
29
|
+
is learned whole, in one bite. `sb.datasets.school()`: 400 pupils, their likes, their
|
|
30
|
+
friendships and their club, made up by smolbrain (`same_club=`, `friends=`).
|
|
31
|
+
|
|
32
|
+
- Chapter 15, "Copying itself": `bro.answers(sb.itself())` (also `autoencoder`) makes a
|
|
33
|
+
brain whose answer is its own input: no answers needed. `bro.copies_of(data)` (also
|
|
34
|
+
`reconstruct`). `sb.fuzzy_middle(size)` (also `Reparameterize`) gives a VAE, and
|
|
35
|
+
`bro.dream(count)` (also `sample`) invents new examples from it. `sb.unshrink(2)`
|
|
36
|
+
(also `Upsample`, `UpSampling2D`) is the opposite of `shrink`. Any layer can add its
|
|
37
|
+
own cost while learning with `self.also_wrong_by(cost)`.
|
|
38
|
+
|
|
39
|
+
- Chapter 14, "Faster": a native engine. `sb.run_on("auto" | "native" | "numpy")` (also
|
|
40
|
+
`set_backend`) chooses what does the math, and `sb.engine()` says which one runs.
|
|
41
|
+
`native` compiles `backend/kernels.c` (plain C99, no library) once with the machine's
|
|
42
|
+
C compiler (`$CC`, cc, gcc or clang) into the cache folder, and loads it with ctypes.
|
|
43
|
+
Squeezed tables (8 and 4 bits) are multiplied straight from their packed bytes for up
|
|
44
|
+
to 4 examples at once, and unpacked in one pass otherwise; everything else stays
|
|
45
|
+
NumPy. Without a compiler, `auto` says why and keeps NumPy. `"gpu"` raises
|
|
46
|
+
`NoGpuError`. Switching engines keeps the random numbers where they were.
|
|
47
|
+
- `x @ squeezed` and `squeezed[words]` go through the engine: a table squeezed to 4 bits
|
|
48
|
+
is never unpacked whole to pick a few rows, or to multiply one example.
|
|
49
|
+
- French: `sb.tourner_sur("natif")`, `sb.moteur()`. Word values are translated when
|
|
50
|
+
given without their setting's name, too.
|
|
51
|
+
|
|
52
|
+
- Chapter 13, "In French": `import smolbrain.fr as sb` gives every existing function,
|
|
53
|
+
class, method and setting its French name from the dictionary (`sb.Cerveau`,
|
|
54
|
+
`bro.se_tromper_moins(fois=3)`, `sb.Bavard(taille="minuscule")`), with the English
|
|
55
|
+
names still working and mixable. French methods are put on the English classes, so a
|
|
56
|
+
brain from `sb.ouvrir` or `sb.invoquer` speaks French too. Errors and warnings come out
|
|
57
|
+
as their French twins (`ErreurPasDeDonnees`, `AlerteParCoeur`...), with the names in
|
|
58
|
+
their advice translated; the sentences stay in English. `sb.Couche` for your own
|
|
59
|
+
layers, with `reflechir(self, x)`. New twins: `ErreurMauvaisFichier`, `AlertePasGarde`.
|
|
60
|
+
- `sb.datasets.moliere()`: 23 of Molière's plays in French, 1,390,146 characters, from his
|
|
61
|
+
complete works on Project Gutenberg, without the editor's notes.
|
|
62
|
+
|
|
63
|
+
- Chapter 12, "Learning a bit more": `sb.summon("smollm2-135m")` (also
|
|
64
|
+
`from_pretrained`) downloads SmolLM2-135M-Instruct (Hugging Face, Apache 2.0) and puts
|
|
65
|
+
its numbers in smolbrain's own layers; any Llama-like model can be summoned from a
|
|
66
|
+
folder with `config.json`, `tokenizer.json` and `model.safetensors` (bfloat16 is read).
|
|
67
|
+
- Conversations: `bro.talk_with(conversation)`, `bro.talk()` in the terminal,
|
|
68
|
+
`chat_with()` (`chat`), `act_like(role)` (`system_prompt`), `remember_up_to(pieces)`
|
|
69
|
+
(`context_length`). The ChatML chat template; the brain stops at its end piece.
|
|
70
|
+
- LoRA: `bro.learn_a_bit_more(text | folder | (question, answer) pairs, times=, rank=8,
|
|
71
|
+
where=("questions", "contents"), window=, fit_in=)` (also `finetune`); QLoRA with
|
|
72
|
+
`fit_in=`; `merge_what_it_learned()` (`merge_lora`); `sb.LittleChange`. From pairs, only
|
|
73
|
+
the answers are learned.
|
|
74
|
+
- `bro.dont_touch(*layers)` (`freeze`) and `bro.touch_again()` (`unfreeze`).
|
|
75
|
+
- `bro.squeeze(4)`: 4-bit weights with a scale per group of 32; `fit_in` tries it last.
|
|
76
|
+
- What real models add, as layer options: `keep_it_steady(center=False)` (`RMSNorm`),
|
|
77
|
+
`pay_attention(share_labels=, spins=, spin_speed=, biases=)` (GQA, RoPE),
|
|
78
|
+
`thinking_block(middle=, gated=, center=, biases=)` (SwiGLU), and `sb.swish` (`silu`).
|
|
79
|
+
- Writing with a brain that spins keeps the labels and contents already read (KV cache).
|
|
80
|
+
- Choppers can start from bytes, with special pieces (GPT-2 style byte-level BPE).
|
|
81
|
+
- `surprise` ignores answers of `-1` ("nothing to guess").
|
|
82
|
+
|
|
83
|
+
### Changed
|
|
84
|
+
|
|
85
|
+
- `sb.what_can_i_afford()` now says the graphics card is not used because smolbrain
|
|
86
|
+
computes with the processor (it said "not used yet (chapter 14)").
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- Pixels are scaled the same way on every machine (the CI failed on macOS), test paths
|
|
91
|
+
work on Windows, and the NumPy backend type-checks with NumPy 2.5.
|
|
92
|
+
|
|
93
|
+
- Chapter 11, "Brains that write": `sb.Blabber(name, size="tiny" | "small" | "medium",
|
|
94
|
+
context=64, chopper=None)` (also `GPT`), a small decoder-only transformer built from
|
|
95
|
+
smolbrain's layers. `bro.here_is_stuff(text)` cuts a text into windows of `context`
|
|
96
|
+
pieces; `be_wrong_less(text, check_with=)`; `how_wrong(text)`;
|
|
97
|
+
`make_stuff_up(prompt, max_pieces=, weirdness=, stop_at=, live=)` (also `generate`,
|
|
98
|
+
with `max_tokens`, `temperature`, `stop`, `stream`); `guess(text)` and
|
|
99
|
+
`how_sure(text, count=5)` for the next piece; `chop`, `unchop`, `count_pieces`.
|
|
100
|
+
Blabbers are kept in `.smol` files with their chopper.
|
|
101
|
+
- `sb.make_chopper(text, pieces=None)` (also `train_tokenizer`): one piece per letter,
|
|
102
|
+
or byte-pair encoding up to `pieces`, glued inside words only. `Chopper.chop`
|
|
103
|
+
(`tokenize`), `numbers` (`encode`), `unchop` (`detokenize`, `decode`), `count_pieces`
|
|
104
|
+
(`count_tokens`).
|
|
105
|
+
- `sb.Text` and `sb.from_text(file)` (also `TextDataset`): a whole text; `sb.split`
|
|
106
|
+
keeps its end for later, without shuffling; `sb.peek` shows its first lines.
|
|
107
|
+
`sb.datasets.shakespeare()` (TinyShakespeare, 1.1 MB).
|
|
108
|
+
- `only_looks_back=True` on `sb.pay_attention` and `sb.thinking_block`: causal attention.
|
|
109
|
+
- `sb.next_word(pieces)`: answers the next piece of text after every piece.
|
|
110
|
+
- `surprise` takes scores of shape `(examples, words, choices)` with answers
|
|
111
|
+
`(examples, words)`.
|
|
112
|
+
- `sb.neurons` works on each word of `(examples, words, numbers)` blocks.
|
|
113
|
+
- Faster `**` (`Backend.power`) and faster `@` of a block of words by a table.
|
|
114
|
+
- `.smol` recipes name the kind of brain, so other kinds can be opened again.
|
|
115
|
+
- Chapter 10, "Paying attention": layers for sentences, shape `(examples, words,
|
|
116
|
+
numbers per word)`. `sb.word_to_numbers(size)` (also `Embedding`), `sb.mash()` (also
|
|
117
|
+
`GlobalAveragePooling1D`), `sb.remembers_order(size, kind="gru" | "simple",
|
|
118
|
+
every_step=False)` (also `GRU`, `RNN`), `sb.pay_attention(heads)` (also
|
|
119
|
+
`MultiHeadAttention`), `sb.position_tag()` (also `PositionalEmbedding`),
|
|
120
|
+
`sb.keep_it_steady()` (also `LayerNorm`), `sb.shortcut(*layers)` (also `Residual`) and
|
|
121
|
+
`sb.thinking_block(heads, wider=4)` (also `TransformerBlock`), a pre-norm block.
|
|
122
|
+
- `sb.from_sentences(sentences, answers, length=)` (also `TextVectorization`): a
|
|
123
|
+
vocabulary, one number per word, `""` to pad and `"?"` for unknown words;
|
|
124
|
+
`Dataset.vocabulary`; `sb.sentences(length, vocabulary)`; `peek` shows sentences;
|
|
125
|
+
`bro.guess("the cat saw the dog")` reads plain text; `.smol` files keep the vocabulary.
|
|
126
|
+
- `sb.datasets.who_did_it(count, chatter=)`: sentences about two animals, made up by
|
|
127
|
+
smolbrain, where only word order tells who did it.
|
|
128
|
+
- `bro.who_looks_at_whom(sentence, layer=, head=)` (also `attention_map`): the
|
|
129
|
+
attention shares, as a table in percent.
|
|
130
|
+
- `@` on blocks of 3 dimensions or more, with broadcasting; `x[index]` with its blame
|
|
131
|
+
(repeated picks add up); `sb.stack(blocks, axis)`; `Backend.put_back()` and `stack()`.
|
|
132
|
+
- `TooMuchChoppingWarning` when a sentence is longer than the brain reads.
|
|
133
|
+
- Chapter 9, "Doing more with less": `bro.budget(data, bite_size=)` (also
|
|
134
|
+
`estimate_memory`) counts the memory learning will take before it starts (numbers,
|
|
135
|
+
blame, the steps' memory, one step, one bite, the data) and says if it fits;
|
|
136
|
+
`sb.what_can_i_afford()` (also `system_info`) gives the memory, free memory and cores.
|
|
137
|
+
- `bro.pretend_bigger_bites(4)` (also `gradient_accumulation`), and
|
|
138
|
+
`pretend_bigger_bites=` in `sb.be_wrong_less`: one step every 4 bites, their blame
|
|
139
|
+
added up.
|
|
140
|
+
- `bro.squeeze(16 / 8)` (also `quantize`): float16, or int8 with one scale per neuron
|
|
141
|
+
(symmetric). Squeezed brains answer but refuse to learn, are kept squeezed in `.smol`
|
|
142
|
+
files, and `weigh()` / `show_me_inside()` say so. `bro.fit_in("150KB")` squeezes just
|
|
143
|
+
enough, or raises `TooBigError`.
|
|
144
|
+
- `Backend.as_kind()`.
|
|
145
|
+
|
|
146
|
+
- Chapter 8, "Seeing things": `sb.pattern_finder(count, size=3, step=1, keep_size=False)`
|
|
147
|
+
(also `Conv2d` / `Conv2D`), a convolution that gives one map per pattern, and
|
|
148
|
+
`sb.shrink(size=2)` (also `MaxPool2d` / `MaxPooling2D`), max pooling. Images are
|
|
149
|
+
channels-last: `(examples, height, width)` or `(examples, height, width, colors)`.
|
|
150
|
+
- `sb.mess_with_it(shift=2, rotate=10, zoom=0.1, flip=False)` (also `augment`,
|
|
151
|
+
`RandomAugment`): a layer that moves, turns, zooms and flips images at random while
|
|
152
|
+
learning only; `.on(data)` messes with a copy of a dataset once, to test a brain.
|
|
153
|
+
- `sb.from_folder(folder, size=, colors=)` (also `ImageFolder`): one subfolder per answer.
|
|
154
|
+
PNG files are read by smolbrain itself (zlib, every filter, palettes, 1 to 16 bits);
|
|
155
|
+
other kinds use Pillow if it's installed. `sb.to_folder(data, folder)` (also
|
|
156
|
+
`save_images`) writes a dataset as PNG files.
|
|
157
|
+
- `bro.what_it_sees(image, layer=)` (also `feature_maps`): draws the maps of a pattern
|
|
158
|
+
finder with characters.
|
|
159
|
+
- `Numbers.windows(size, step, pad)` (also `unfold`), with its backward rule;
|
|
160
|
+
`Backend.windows()`, `add_windows()` and `pick_pixels()`.
|
|
161
|
+
- `.smol` recipes know `pattern_finder`, `shrink` and `mess_with_it`; `show_me_inside`
|
|
162
|
+
gives the shape of every map.
|
|
163
|
+
|
|
164
|
+
- Chapter 7, "Keeping a brain around": `bro.keep(file)` (also `save`) and `sb.open(file)`
|
|
165
|
+
(also `sb.load`) write and read `.smol` files: safetensors files, with the brain's recipe
|
|
166
|
+
(layers, answers, settings, history, diary) and a SHA-256 fingerprint in the metadata.
|
|
167
|
+
Opening one never runs code. Writes go to a draft file first, then replace the old one.
|
|
168
|
+
- `bro.weigh()` (also `size`): how many numbers, in memory and on disk.
|
|
169
|
+
- `sb.keep_numbers(layer, file)` / `sb.open_numbers(layer, file)` (also `save_weights` /
|
|
170
|
+
`load_weights`) for layers you wrote yourself; `Layer.what_it_knows()` (also
|
|
171
|
+
`state_dict`) and `Layer.remember()` (also `load_state_dict`).
|
|
172
|
+
- `BadFileError` (not a `.smol` file, damaged, or made by a newer smolbrain) and
|
|
173
|
+
`NotKeptWarning` (your own judge or steps can't go in a file).
|
|
174
|
+
- `Backend.read_bytes()` and `to_bytes()`.
|
|
175
|
+
- `why()` now describes the whole training history, not only the last `be_wrong_less`;
|
|
176
|
+
`Neurons.inputs` is read from the weights' shape.
|
|
177
|
+
|
|
178
|
+
- Chapter 6, "Did it really learn?": `bro.prove_it(data)` (also `evaluate`, compares with
|
|
179
|
+
a lazy brain that always gives the most common answer), `bro.how_sure(x)` (also
|
|
180
|
+
`predict_proba`), `bro.where_it_fails(data)` (also `confusion_matrix`),
|
|
181
|
+
`bro.worst_guesses(data, n)` (also `top_errors`, returns a dataset),
|
|
182
|
+
`bro.what_it_looks_at(example)` (also `saliency_map`), `bro.show_progress()` (also
|
|
183
|
+
`plot_history`, a chart in characters, or matplotlib with `picture=True`), `bro.why()`
|
|
184
|
+
(also `explain`, every decision the brain made by itself), and `bro.predict`.
|
|
185
|
+
- `be_wrong_less(..., check_with=data)`: a loss on data the brain doesn't learn from, after
|
|
186
|
+
each round, in `history.check_losses`; `stop_when_bored` watches it.
|
|
187
|
+
- `MemorizedItWarning` from `prove_it`, when the brain is 10 points better on what it
|
|
188
|
+
learned from than on new examples.
|
|
189
|
+
- `smolbrain.observe`: `Proof`, `HowSure`, `Confusion`, `Diary`, `progress_chart`,
|
|
190
|
+
`progress_picture`, `blame_map`, `what_mattered`, `draw_blame`.
|
|
191
|
+
- `Dataset.example(i)`, one example ready for `guess`; `sb.peek`'s drawing helpers are
|
|
192
|
+
public (`draw_image`, `side_by_side`).
|
|
193
|
+
- Chapter 5, "What the brain learns from": `sb.Dataset`, `sb.from_lists`, `sb.from_csv`
|
|
194
|
+
(also `read_csv`), `sb.split`, `sb.shuffle`, `sb.peek` (also `head`, draws images with
|
|
195
|
+
characters), `Dataset.right_answers()`, and `bro.here_is_stuff(data)`.
|
|
196
|
+
- Built-in datasets: `sb.datasets.flowers()` (bundled), `houses()`, `digits()` and
|
|
197
|
+
`clothes()` (downloaded once to `~/.cache/smolbrain` or `$SMOLBRAIN_HOME`, checked by
|
|
198
|
+
SHA-256).
|
|
199
|
+
- `sb.make_it_fair()` (also `Normalization`): a layer that learns the scale of each column
|
|
200
|
+
from the training data, with `fill_missing=True`. `Layer.get_to_know()` (also `adapt`).
|
|
201
|
+
- `bro.be_wrong_less()` takes a dataset, or uses `here_is_stuff`; above 1,000 examples it
|
|
202
|
+
learns in bites of 32. Missing values are explained (`BadDataError`).
|
|
203
|
+
- `Backend.from_bytes()`, `where()` and `is_missing()`.
|
|
204
|
+
- Chapter 4, "Building a brain": `sb.Brain` (also `Model`) with `looks_at` (`sb.columns`,
|
|
205
|
+
`sb.image`), `thinks_with`, `answers` (`sb.one_of`, `sb.yes_or_no`, `sb.some_of`,
|
|
206
|
+
`sb.a_number`, with named choices), `forget_on_purpose`, `show_me_inside`, `guess`,
|
|
207
|
+
`be_wrong_less`, `how_wrong`, `history`, and the settings `learns_like`, `judged_by`,
|
|
208
|
+
`calm_down`, `slow_down_over_time`, `stop_when_bored`.
|
|
209
|
+
- `sb.Brain` shortcuts: `looks_at(8)` / `looks_at((28, 28))`, `thinks_with(16, 16)`,
|
|
210
|
+
`answers("cat", "dog")`. Without `looks_at` or `answers`, the brain guesses them from the
|
|
211
|
+
data on its first `be_wrong_less`, and prints what it guessed (it refuses to guess when
|
|
212
|
+
whole numbers 0, 1, 2... could be choices or amounts).
|
|
213
|
+
- `sb.forget_on_purpose` (also `Dropout`), active only inside `learning_mode()`.
|
|
214
|
+
- `WrongThingError` (and `ErreurMauvaiseChose`), for the wrong kind of thing.
|
|
215
|
+
- `Backend.chance()`: random numbers between 0 and 1.
|
|
216
|
+
- Chapter 3, "Being wrong less": `sb.be_wrong_less` (also `train`) with `times`, `judged_by`,
|
|
217
|
+
`learns_like`, `step`, `carefully`, `bite_size`, `calm_down`, `slow_down_over_time`,
|
|
218
|
+
`stop_when_bored` and `quiet`; it returns a `History`. `sb.how_wrong` (also `compute_loss`).
|
|
219
|
+
- Judges: `squared_error` (`mse`), `surprise` (`cross_entropy`), `yes_no_surprise`
|
|
220
|
+
(`binary_cross_entropy`).
|
|
221
|
+
- Optimizers: `SmartSteps` (`Adam`, AdamW with `shrink_weights`), `PlainSteps` (`SGD`, with
|
|
222
|
+
momentum). `calm_down` (`clip_gradients`) and a cosine step schedule.
|
|
223
|
+
- `GaveUpError` when the loss explodes, `NotLearningWarning` when it doesn't move.
|
|
224
|
+
- Chapter 2, "Neurons and layers": `sb.Layer` (`think`, `learnable`, `forget_blame`),
|
|
225
|
+
`sb.neurons` (also `Dense` / `Linear`), `sb.flatten`, and the activations
|
|
226
|
+
`ignore_negatives`, `smooth_ignore_negatives`, `squash01`, `squash_both_ways`,
|
|
227
|
+
`into_percentages` (also `relu`, `gelu`, `sigmoid`, `tanh`, `softmax`).
|
|
228
|
+
- `Numbers`: comparisons, `tanh()`, `max()`.
|
|
229
|
+
- `sb.same_luck` (also `seed`), for repeatable random numbers.
|
|
230
|
+
- Chapter 1, "Your brain is just numbers": `Numbers` (tensors), `sb.numbers`, `sb.zeros`,
|
|
231
|
+
`sb.ones`, `sb.random`, arithmetic with broadcasting, `@`, `sum`, `mean`, `reshape`,
|
|
232
|
+
`flatten`, `transpose`, `exp`, `log`, and autograd (`find_who_to_blame`, `no_blame`),
|
|
233
|
+
with serious aliases (`tensor`, `backward`, `grad`, `no_grad`, ...).
|
|
234
|
+
- `NothingToBlameError` (and `ErreurRienABlamer`).
|
|
235
|
+
- The NumPy backend, behind the `Backend` protocol.
|
|
236
|
+
- The book: a VitePress site in `docs/`, in English and French, with chapter 1.
|
|
237
|
+
|
|
238
|
+
- Project skeleton: `src` layout, layered architecture checked by import-linter.
|
|
239
|
+
- Errors and warnings that teach (`smolbrain.errors`), with French twins (`smolbrain.fr`).
|
|
240
|
+
- Dictionaries (EN/FR), architecture notes, first ADRs, roadmap.
|
|
241
|
+
- Logo: the pixel brain and the `smo\Bra!n` wordmark (`docs/public/`).
|
|
242
|
+
|
|
243
|
+
### Fixed
|
|
244
|
+
|
|
245
|
+
- Backward rules receive their result (`backward(out)`) instead of holding it in a
|
|
246
|
+
closure: no more reference cycles, so a finished calculation is freed at once. Learning
|
|
247
|
+
the seeing digits brain went from about 1 GB to under 100 MB.
|
|
248
|
+
- Checking for missing values no longer copies the data (one sum first, then rows).
|
|
249
|
+
- Blame is no longer copied when it is already the right kind.
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
## Setup
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
make install
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
This creates `.venv`, installs smolbrain in editable mode with dev tools, and installs the pre-commit hooks.
|
|
10
|
+
|
|
11
|
+
## Before opening a pull request
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
make check
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
It runs, in order: format check, lint (ruff), types (mypy, strict), architecture rules (import-linter), tests (pytest).
|
|
18
|
+
|
|
19
|
+
## Rules
|
|
20
|
+
|
|
21
|
+
1. **Respect the layers.** A package never imports from a package above it. See [docs/project/architecture.md](docs/project/architecture.md).
|
|
22
|
+
2. **Errors teach.** Raise a `smolbrain.errors` class, and fill `try_this` when there is something to try.
|
|
23
|
+
3. **Names are honest.** A fun name must say what the function really does, and needs a serious alias.
|
|
24
|
+
4. **Update the dictionaries.** A new public function goes in `docs/reference/dictionary.md` *and* `docs/fr/reference/dictionnaire.md`.
|
|
25
|
+
5. **Tests come with the code.** `tests/unit/` mirrors `src/smolbrain/`.
|
|
26
|
+
6. **Big decisions get an ADR** in `docs/project/adr/`.
|
|
27
|
+
7. **The book follows the code.** A finished chapter gets its page in `docs/book/` and `docs/fr/livre/`. Run `make docs` to preview it.
|
|
28
|
+
|
|
29
|
+
## Commit messages
|
|
30
|
+
|
|
31
|
+
[Conventional Commits](https://www.conventionalcommits.org/): `feat(core): add matmul backward`, `fix(errors): ...`, `docs: ...`.
|
smolbrain-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 JonGaius
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
smolbrain-0.1.0/Makefile
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
.DEFAULT_GOAL := help
|
|
2
|
+
VENV := .venv
|
|
3
|
+
BIN := $(VENV)/bin
|
|
4
|
+
|
|
5
|
+
.PHONY: help install format lint typecheck imports test cov check docs docs-build clean
|
|
6
|
+
|
|
7
|
+
help: ## Show this help
|
|
8
|
+
@grep -E '^[a-z]+:.*## ' $(MAKEFILE_LIST) | awk -F ':.*## ' '{printf " \033[36m%-10s\033[0m %s\n", $$1, $$2}'
|
|
9
|
+
|
|
10
|
+
install: ## Create the virtualenv, install smolbrain (editable) and the git hooks
|
|
11
|
+
python3 -m venv $(VENV)
|
|
12
|
+
$(BIN)/pip install --upgrade pip
|
|
13
|
+
$(BIN)/pip install -e ".[dev,plot]"
|
|
14
|
+
-$(BIN)/pre-commit install
|
|
15
|
+
|
|
16
|
+
format: ## Format the code
|
|
17
|
+
$(BIN)/ruff format src tests
|
|
18
|
+
$(BIN)/ruff check --fix src tests
|
|
19
|
+
|
|
20
|
+
lint: ## Check style and common bugs
|
|
21
|
+
$(BIN)/ruff format --check src tests
|
|
22
|
+
$(BIN)/ruff check src tests
|
|
23
|
+
|
|
24
|
+
typecheck: ## Check types (strict)
|
|
25
|
+
$(BIN)/mypy
|
|
26
|
+
|
|
27
|
+
imports: ## Check the layered architecture
|
|
28
|
+
$(BIN)/lint-imports
|
|
29
|
+
|
|
30
|
+
test: ## Run the tests
|
|
31
|
+
$(BIN)/pytest
|
|
32
|
+
|
|
33
|
+
cov: ## Run the tests with coverage
|
|
34
|
+
$(BIN)/pytest --cov --cov-report=term-missing
|
|
35
|
+
|
|
36
|
+
check: lint typecheck imports test ## Everything CI runs
|
|
37
|
+
|
|
38
|
+
docs: ## Preview the book locally (VitePress)
|
|
39
|
+
cd docs && npm install && npm run dev
|
|
40
|
+
|
|
41
|
+
docs-build: ## Build the book, failing on dead links
|
|
42
|
+
cd docs && npm ci && npm run build
|
|
43
|
+
|
|
44
|
+
clean: ## Remove caches and build artifacts
|
|
45
|
+
rm -rf build dist .pytest_cache .mypy_cache .ruff_cache .import_linter_cache .coverage htmlcov
|
|
46
|
+
find . -type d -name __pycache__ -prune -exec rm -rf {} +
|