bertuner 0.1.2__tar.gz → 0.2.1__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.
- {bertuner-0.1.2 → bertuner-0.2.1}/PKG-INFO +10 -1
- {bertuner-0.1.2 → bertuner-0.2.1}/README.md +9 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/BERTuner.py +450 -133
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/CustomTrainer.py +89 -3
- bertuner-0.2.1/bertuner/__init__.py +15 -0
- bertuner-0.2.1/bertuner/exceptions.py +50 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner.egg-info/PKG-INFO +10 -1
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner.egg-info/SOURCES.txt +2 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/pyproject.toml +1 -1
- bertuner-0.2.1/tests/test_numerical_stability.py +339 -0
- bertuner-0.1.2/bertuner/__init__.py +0 -8
- {bertuner-0.1.2 → bertuner-0.2.1}/LICENSE +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/Predictor.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/TensorBoardCallback.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/constants.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner/utils.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner.egg-info/dependency_links.txt +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner.egg-info/requires.txt +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/bertuner.egg-info/top_level.txt +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/setup.cfg +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/tests/test_bertuner.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/tests/test_predictor.py +0 -0
- {bertuner-0.1.2 → bertuner-0.2.1}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bertuner
|
|
3
|
-
Version: 0.1
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Summary: Hyperparameter optimization and fine-tuning for BERT-style text classifiers (Optuna + MLflow), with long-context ModernBERT support
|
|
5
5
|
Author-email: elemets <alafunnell@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -82,6 +82,9 @@ classifier = BERTuneClassifier(
|
|
|
82
82
|
text_feature="text_col", # column containing the text
|
|
83
83
|
target_cols=["label_col"], # one column = single-label
|
|
84
84
|
max_length=512,
|
|
85
|
+
precision="auto", # BF16/FP16 on supported CUDA, else FP32
|
|
86
|
+
retry_nonfinite_in_fp32=True, # retry verified NaN/Inf failures once
|
|
87
|
+
max_grad_norm=1.0, # explicit gradient clipping threshold
|
|
85
88
|
)
|
|
86
89
|
|
|
87
90
|
# 2. Configure (optional: uses defaults if called without arguments)
|
|
@@ -106,6 +109,12 @@ Multi-label classification: pass several target columns — `target_cols=["l1",
|
|
|
106
109
|
|
|
107
110
|
Grouped data (e.g. multiple notes per patient): pass `group_key="patient_id"` and the train/val/test split guarantees no group leaks across splits.
|
|
108
111
|
|
|
112
|
+
### Numerical-stability recovery
|
|
113
|
+
|
|
114
|
+
Every attempt checks logits, loss, gradients before the optimizer step, and evaluation predictions for NaN/Inf. When a mixed-precision attempt becomes non-finite, BERTuner deletes its checkpoints, reloads the pretrained model, resets the seed, and retries the same Optuna trial and hyperparameters once in FP32. A second numerical failure prunes an optimization trial; final-model training raises `NonFiniteTrainingError`. Invalid labels, class weights, OOM errors, and other exceptions never trigger the retry.
|
|
115
|
+
|
|
116
|
+
`precision` accepts `"auto"`, `"fp32"`, `"bf16"`, or `"fp16"`. Explicit unsupported precision raises before training. Set `retry_nonfinite_in_fp32=False` to disable recovery, `max_grad_norm=None` to disable clipping, or `class_weight_warning_threshold=None` to disable warnings for large finite class weights. Saved `bertuner_config.json` records requested/effective precision and fallback status.
|
|
117
|
+
|
|
109
118
|
### Metrics logged to MLflow
|
|
110
119
|
|
|
111
120
|
Final runs log one canonical metric set for both `Validation_*` and `Test_*`:
|
|
@@ -41,6 +41,9 @@ classifier = BERTuneClassifier(
|
|
|
41
41
|
text_feature="text_col", # column containing the text
|
|
42
42
|
target_cols=["label_col"], # one column = single-label
|
|
43
43
|
max_length=512,
|
|
44
|
+
precision="auto", # BF16/FP16 on supported CUDA, else FP32
|
|
45
|
+
retry_nonfinite_in_fp32=True, # retry verified NaN/Inf failures once
|
|
46
|
+
max_grad_norm=1.0, # explicit gradient clipping threshold
|
|
44
47
|
)
|
|
45
48
|
|
|
46
49
|
# 2. Configure (optional: uses defaults if called without arguments)
|
|
@@ -65,6 +68,12 @@ Multi-label classification: pass several target columns — `target_cols=["l1",
|
|
|
65
68
|
|
|
66
69
|
Grouped data (e.g. multiple notes per patient): pass `group_key="patient_id"` and the train/val/test split guarantees no group leaks across splits.
|
|
67
70
|
|
|
71
|
+
### Numerical-stability recovery
|
|
72
|
+
|
|
73
|
+
Every attempt checks logits, loss, gradients before the optimizer step, and evaluation predictions for NaN/Inf. When a mixed-precision attempt becomes non-finite, BERTuner deletes its checkpoints, reloads the pretrained model, resets the seed, and retries the same Optuna trial and hyperparameters once in FP32. A second numerical failure prunes an optimization trial; final-model training raises `NonFiniteTrainingError`. Invalid labels, class weights, OOM errors, and other exceptions never trigger the retry.
|
|
74
|
+
|
|
75
|
+
`precision` accepts `"auto"`, `"fp32"`, `"bf16"`, or `"fp16"`. Explicit unsupported precision raises before training. Set `retry_nonfinite_in_fp32=False` to disable recovery, `max_grad_norm=None` to disable clipping, or `class_weight_warning_threshold=None` to disable warnings for large finite class weights. Saved `bertuner_config.json` records requested/effective precision and fallback status.
|
|
76
|
+
|
|
68
77
|
### Metrics logged to MLflow
|
|
69
78
|
|
|
70
79
|
Final runs log one canonical metric set for both `Validation_*` and `Test_*`:
|