feat: activate Focal Loss, add Dice Loss + span-width weighting, OpenVINO INT8 pipeline#361
Open
ALI-AL-MARJANI wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
1. Loss functions (
gliner/modeling/loss_functions.py,base.py,trainer.py)focal_loss_with_logitsalready exists in the codebase but is disabled by default(
alpha=-1, gamma=0). This PR:loss_type,focal_loss_alpha,focal_loss_gammainTrainingArgumentssousers can activate it
span_dice_loss()— span-level Dice Loss adapted from Li et al. (ACL 2020),applied element-wise over the
(B, L×K, T)logit tensor withignore_indexmaskinguse_span_width_weightflag: positive spans of width k receivew(k) = 1 + log(k+1)— zero inference overheadMotivation: WNUT-17 has 187× more negative spans than positive entities (0.53%
positive ratio). BCE's gradient is dominated by trivial negatives. Focal α=0.25 delivers
+0.99 pp WNUT-17 F1; Dice delivers +0.70 pp.
2. Bug fixes (
gliner/utils.py,gliner/modeling/encoder.py,gliner/model.py,gliner/onnx/model.py)is_module_available()changed from__import__()toimportlib.util.find_spec()—prevents optional packages (peft, tensorflow) from being eagerly imported, which caused
OpenMP deadlocks on macOS ARM
encoder.py:kwargs.pop("token_lengths", None)prevents crash on bi-encoder modelsthat pass this GLiNER-internal kwarg to HuggingFace forward methods
Trainer/TrainingArgumentsinmodel.py— avoids importingtorch.distributed at module load time
3. OpenVINO INT8 pipeline (
scripts/convert_to_openvino.py)New script: ONNX → OpenVINO IR → INT8 weight compression via
nncf.compress_weights(INT8_ASYM).contains
Ifnodes with dynamic rank that the CPU plugin rejects during calibration-basedquantization
Benchmark
Model:
knowledgator/gliner-bi-small-v1.0, 200 fine-tuning steps on CoNLL-2003, eval onWNUT-17.