File size: 3,482 Bytes
2d52135
 
 
 
b22e8ba
dc8d52b
 
2d52135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b22e8ba
 
 
 
2d52135
 
 
 
 
 
 
 
dc8d52b
 
2d52135
 
 
 
dc8d52b
2d52135
 
dc8d52b
 
2d52135
 
 
 
 
 
dc8d52b
 
2d52135
dc8d52b
 
2d52135
 
 
 
 
 
e64ea16
 
 
2d52135
 
e64ea16
 
 
2d52135
 
 
 
 
 
 
 
 
dc8d52b
2d52135
 
 
 
dc8d52b
b22e8ba
dc8d52b
 
b22e8ba
dc8d52b
b22e8ba
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
ENV?=mini-transformer
CONDA_RUN=conda run -n $(ENV)
PYTHON?=python

.PHONY: help create-env install precommit lint lint-check fmt fmt-check type test cov fetch-test fetch-small infer serve ui clean clean-all docker-build-dev docker-run-dev docker-build-infer docker-run-infer

help:
	@echo "Available targets:"
	@echo "  create-env     - Create or update the $(ENV) conda environment"
	@echo "  install        - Install project with dev/notebook/viz extras into the active environment"
	@echo "  precommit      - Run all pre-commit hooks"
	@echo "  lint           - Run ruff lint (auto-fixes with fmt beforehand)"
	@echo "  lint-check     - Run ruff in check-only mode"
	@echo "  fmt            - Format code with ruff + black"
	@echo "  fmt-check      - Check formatting without modifying files"
	@echo "  type           - Run mypy type checks"
	@echo "  test           - Run unit tests"
	@echo "  cov            - Run unit tests with coverage report"
	@echo "  fetch-test     - Download the AlaBoussoffara/transformer_test model"
	@echo "  fetch-small    - Download the AlaBoussoffara/transformer_small model"
	@echo "  infer          - Quick inference using the demo model"
	@echo "  serve          - Start the FastAPI server (reload mode)"
	@echo "  ui             - Launch the Chainlit UI"
	@echo "  clean          - Remove build/test caches"
	@echo "  clean-all      - Clean caches plus notebooks outputs"
	@echo "  docker-build-dev   - Build the development Docker image"
	@echo "  docker-run-dev     - Drop into the development container"
	@echo "  docker-build-infer - Build the inference Docker image"
	@echo "  docker-run-infer   - Run the inference container exposing the Chainlit UI"

create-env:
	conda env create -n $(ENV) -f environment.yml || conda env update -n $(ENV) -f environment.yml
	$(CONDA_RUN) pip install -e .[dev,notebook,viz]
	$(CONDA_RUN) pre-commit install

install:
	$(PYTHON) -m pip install -e .[dev,notebook,viz]

precommit:
	$(CONDA_RUN) pre-commit run --all-files

lint: fmt
	$(CONDA_RUN) ruff check .

lint-check:
	$(CONDA_RUN) ruff check .

fmt:
	$(CONDA_RUN) ruff format .
	$(CONDA_RUN) black src tests

fmt-check:
	$(CONDA_RUN) ruff format . --check
	$(CONDA_RUN) black src tests --check

type:
	$(CONDA_RUN) mypy src

test:
	$(CONDA_RUN) pytest

cov:
	$(CONDA_RUN) pytest --cov=mini_transformer --cov-report=term-missing

fetch-test:
	mini-transformer-fetch AlaBoussoffara/transformer_test --force
	cp -rf ./trained_models/AlaBoussoffara__transformer_test/test_model_v1 ./trained_models/test_model_v1
	rm -rf ./trained_models/AlaBoussoffara__transformer_test

fetch-small:
	mini-transformer-fetch AlaBoussoffara/transformer_small --force
	cp -rf ./trained_models/AlaBoussoffara__transformer_small/small_model_v1 ./trained_models/small_model_v1
	rm -rf ./trained_models/AlaBoussoffara__transformer_small/
infer:
	$(CONDA_RUN) mini-transformer-infer --model small_model_v1 -t "translate this sentence."

serve:
	$(CONDA_RUN) mini-transformer-serve --model small_model_v1 --reload

ui:
	$(CONDA_RUN) mini-transformer-ui --model small_model_v1 --host 0.0.0.0 --port 8000

clean:
	rm -rf .pytest_cache .mypy_cache .ruff_cache dist build *.egg-info

clean-all: clean
	rm -rf notebooks/.ipynb_checkpoints outputs/*

docker-build-dev:
	docker compose build dev --no-cache

docker-run-dev:
	docker compose run --rm dev bash

docker-build-infer:
	docker compose build infer --no-cache

docker-run-infer:
	docker compose run --rm --service-ports infer