Introduction
This repository contains AI libraries commonly used for all my AI projects.
Train
The MyTrain class train subclass of huggingface PreTrainedModel. model.state_dict and model.load_state_dict must be consistent.
---
title: MyTrain.__call__
---
flowchart TD
INST[instantiate model and random generator] --> TRAININSTMETRICS[instantiate metrics] --> MODE{{evaluation only?}}
MODE -- yes --> EVALMODEL[<code>MyTrain.my_eval_model</code>]
subgraph EVALMODEL[<code>MyTrain.my_eval_model</code>]
direction TB
EVALLOOP[eval loop]
end
subgraph EVALLOOP[eval loop]
direction TB
CHECKCONSISTENCY[check config consistency] --> EVALLOADCHECKPOINT[load checkpoint for model and generator] --> EVALDEVICE[set model device] --> EVALDATALOADER[setup data loader] --> EVALEPOCHBRANCH{{implement <code>model.my_eval_epoch</code>?}}
EVALEPOCHBRANCH -- yes --> CUSTOMEVAL[<code>model.my_eval_epoch</code>]
EVALEPOCHBRANCH -- no --> COMMONEVAL[<code>MyTrain.my_eval_epoch</code>]
CUSTOMEVAL --> UPDATECONFIGPERFORM[update configuration]
COMMONEVAL --> UPDATECONFIGPERFORM
end
MODE -- no --> COMMONTRAIN[<code>MyTrain.my_train_model</code>]
subgraph COMMONTRAIN[<code>MyTrain.my_train_model</code>]
direction TB
CONTINUETRAIN{{last epoch is -1?}}
CONTINUETRAIN -- yes --> HASINIT{{implement <code>model.my_initialize_model</code>?}} -- yes --> CUSTOMINIT[<code>model.my_initialize_model</code>?]
HASINIT -- no --> INITWEIGHT[initialize model weights by <code>my_initializer</code>]
CONTINUETRAIN -- no --> TRAINLOADCHECK[load checkpoint for model and random generator]
CUSTOMINIT --> TRAINDEVICE[set model device]
INITWEIGHT --> TRAINDEVICE
TRAINLOADCHECK --> TRAINDEVICE
TRAINDEVICE --> INSTOPSC[instantiate optimizer and lr scheduler] --> CONTINUETRAIN2{{last epoch is -1?}} -- no --> TRAINCHECKOPSC[load checkpoint for optimizer and lr scheduler] --> SETUPOPSC[setup optimizer and lr_scheduler]
CONTINUETRAIN2{{last epoch is -1?}} -- yes --> SETUPOPSC
SETUPOPSC --> TRAINDATALOADER[setup data loader] --> INSTEARLYSTOP[instantiate early stopping] --> TRAINLOOP[train loop]
end
subgraph TRAINLOOP[train loop]
direction TB
M{{implement <code>model.my_train_epoch</code>?}}
M -- yes --> N[<code>model.my_train_epoch</code>]
M -- no --> O[<code>MyTrain.my_train_epoch</code>]
N --> P{{implement <code>model.my_eval_epoch</code>?}}
O --> P
P -- yes --> Q[<code>model.my_eval_epoch</code>]
P -- no --> R[<code>MyTrain.my_eval_epoch</code>]
Q --> UPDATELR[update learning rate]
R --> UPDATELR
UPDATELR --> TRAINSAVE[save epoch configuration and checkpoint] --> EARLYSTOP[check early stopping]
end
Test
The MyTest class test subclass of huggingface PreTrainedModel. MyTest will load the epoch saved by MyTrain. If model.my_train_model is implemented, then the corresponding model.my_load_model is necessary.
---
title: MyTest.__call__
---
flowchart TD
INSTMODEL[instantiate model and random generator] --> INSTMETRIC[instantiate metrics] --> LOADCHECK[load checkpoint for model and random generator] --> TESTDEVICE[set model device] --> TESTDATA[setup data loader] --> TESTMODEL[test model] --> TESTSAVE[save metrics]
Metric
The metric classes should implement three methods.
__init__intialized the parameters and metric state.stepprocess the batchs. It receives:df: the data frame returned by the model'seval_outputmethod.examples: the examples in the dataset.batch: the batch returned by the model'sdata_collator.
epochaccumulate all batch results, reinitialize the metric state and return the final metric.
Metadata
Release files for common-ai 0.1.21
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| common_ai-0.1.21.tar.gz | 33.8 kB | With provenance | Details for common_ai-0.1.21.tar.gz |
Release files / common_ai-0.1.21.tar.gz
| Download URL | common_ai-0.1.21.tar.gz |
|---|---|
| Size | 33.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d623092a15bb29039578195c4bd34fa928c50b91b89193ed9f54d68a9f7c2e0
|
|
BLAKE2b-256 checksum How to use checksums |
886b38ef1cc386c69c3c3ccd27dd716141813d5f07bcc77a3fb7206c07941b61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.
Transparency logSecurity for common-ai 0.1.21
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 1 file in this release has been uploaded with provenance metadata.
Attestation for common_ai-0.1.21.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 16, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.