This project has been archived by its maintainers, and is no longer receiving any updates.
ood
주피터 노트북에서 PyTorch 모델을 객체지향으로 다루기 위한 얇은 보조 라이브러리.
모델은 유저가 PyTorch로 직접 작성한다. 이 라이브러리는 그 주변만 담당한다 — 하이퍼파라미터 자동 저장, 셀 간 메서드 추가, 학습 중 손실 곡선 라이브 렌더링, 디바이스 자동 선택, 체크포인트.
설치
pip install ood-dl
배포 이름은 ood-dl, import 이름은 ood 다. PyPI 에 ood 이름이 이미 쓰이고 있어서다.
import ood as od
이 저장소에서 직접 개발하려면:
uv sync
퀵스타트
import torch
from torch import nn
from torch.nn import functional as F
import ood as od
class SyntheticRegression(od.DataModule):
def __init__(self, n=200, batch_size=32):
super().__init__()
self.save_hyperparameters()
torch.manual_seed(0)
self.X = torch.randn(n, 2)
self.y = self.X @ torch.tensor([[2.0], [-3.4]]) + 4.2
def get_dataloader(self, train):
idx = slice(0, 160) if train else slice(160, None)
return self.get_tensorloader((self.X, self.y), train, idx)
class LinearRegression(od.Module):
def __init__(self, lr=0.03):
super().__init__()
self.save_hyperparameters()
self.net = nn.LazyLinear(1)
다음 셀에서 메서드를 덧붙인다. 클래스를 다시 정의할 필요가 없다.
@od.add_to_class(LinearRegression)
def loss(self, y_hat, y):
return F.mse_loss(y_hat, y)
@od.add_to_class(LinearRegression)
def configure_optimizers(self):
return torch.optim.SGD(self.parameters(), lr=self.lr)
학습을 돌리면 손실 곡선이 셀 출력에 실시간으로 갱신된다.
trainer = od.Trainer(max_epochs=20)
trainer.fit(LinearRegression(), SyntheticRegression())
trainer.save_checkpoint("linreg.pt")
전체 예제는 examples/quickstart.ipynb 참고.
API
| 이름 | 역할 |
|---|---|
od.add_to_class(Class) |
데코레이트한 함수를 Class 의 메서드로 등록 |
od.HyperParameters |
save_hyperparameters() 로 __init__ 인자를 속성 + hparams 로 저장 |
od.DataModule |
get_dataloader(train) 하나만 구현하면 되는 데이터 규약 |
od.Module |
forward/loss/configure_optimizers 를 채우는 모델 규약 |
od.Trainer |
fit(model, data), save_checkpoint, load_checkpoint, history |
od.ProgressBoard |
라이브 손실 곡선. Trainer(plot=True) 가 자동으로 만든다 |
od.default_device() |
cuda → mps → cpu |
개발
uv run pytest
라이센스
MIT. LICENSE 참고.
설계는 d2l-ai/d2l-en의 d2l/torch.py를 참고했다.
해당 샘플 코드는 modified MIT(LICENSE-SAMPLECODE)로 배포된다.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ood_dl-0.1.0.tar.gz.
File metadata
- Download URL: ood_dl-0.1.0.tar.gz
- Upload date:
- Size: 78.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74ee29b4343bdcb2ebe9956753705d31a08528d52ebae2686ca4407711eb7456
|
|
| MD5 |
22800564fc16073cec79f8548ce3611c
|
|
| BLAKE2b-256 |
18c1727ef89a5a133354dc992942c9872038ce0b69becf739fc9ade9ffd8f766
|
Provenance
The following attestation bundles were made for ood_dl-0.1.0.tar.gz:
Publisher:
publish.yml on sciencemj/ood-dl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ood_dl-0.1.0.tar.gz -
Subject digest:
74ee29b4343bdcb2ebe9956753705d31a08528d52ebae2686ca4407711eb7456 - Sigstore transparency entry: 2313962001
- Sigstore integration time:
-
Permalink:
sciencemj/ood-dl@c6c3e789b0a323ca8ff86a4ba6359d78f9015833 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sciencemj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6c3e789b0a323ca8ff86a4ba6359d78f9015833 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ood_dl-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ood_dl-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1cae0c260edd5cd3c04a168c01846c4efa15a820fa62c27c7639cbed8c08d4ff
|
|
| MD5 |
ca2e3351a06a0aed5f596f5055e86126
|
|
| BLAKE2b-256 |
0bda21ff58a8732ebfeefa9921c88f56821bf31071e51162df605f3fdc21f333
|
Provenance
The following attestation bundles were made for ood_dl-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on sciencemj/ood-dl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ood_dl-0.1.0-py3-none-any.whl -
Subject digest:
1cae0c260edd5cd3c04a168c01846c4efa15a820fa62c27c7639cbed8c08d4ff - Sigstore transparency entry: 2313962035
- Sigstore integration time:
-
Permalink:
sciencemj/ood-dl@c6c3e789b0a323ca8ff86a4ba6359d78f9015833 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sciencemj
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c6c3e789b0a323ca8ff86a4ba6359d78f9015833 -
Trigger Event:
release
-
Statement type: