Metadata-Version: 2.4
Name: opake-transformers
Version: 0.16.0
Summary: Hugging Face trainer integration for Opake: DP-aware training loop, TRL-style SFT/DPO support, and Hugging Face compatibility layers.
Author: Opake Contributors
License: Apache-2.0
Keywords: differential-privacy,huggingface,transformers,pytorch,privacy,machine-learning
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Requires-Python: <3.14,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: transformers<6,>=5.0.0
Requires-Dist: peft>=0.13.0
Requires-Dist: datasets>=2.0.0
Requires-Dist: numpy>=1.24
Requires-Dist: opake-engine==0.16.0
Requires-Dist: opake-patches==0.16.0
Requires-Dist: opake-dpsgd==0.16.0
Requires-Dist: opake-dpftrl==0.16.0
Requires-Dist: opake-accounting==0.16.0
Requires-Dist: opake-optimizers==0.16.0
Requires-Dist: opake-alignment==0.16.0
Provides-Extra: trl
Requires-Dist: trl<2.0,>=1.0; extra == "trl"
Dynamic: license-file

# opake-transformers

Hugging Face trainer integration for Opake: DP-aware training loop
(`opake.transformers.trainer.DPTrainer`) with TRL-style SFT/DPO support
(`opake.transformers.trl`) and Hugging Face compatibility layers.

## Install

Install the root package as described in the [repository installation guide](https://github.com/JetBrains-Research/opake#installation).
Use its `transformers` extra for trainer integration or `trl` for TRL config
conversion.

Depends on `opake-engine`, `opake-patches`, `opake-dpsgd`, `opake-dpftrl`,
`opake-accounting`, `opake-optimizers`, `opake-alignment`, plus
`transformers>=5.0`, `peft>=0.13`, and `datasets>=2.0`.

For Triton fused kernels (RoPE, RMSNorm, activation, cross-entropy), install
`opake-patches[transformers]` — kernels are a dependency of `opake-patches`
and gate on CUDA + Triton at runtime.

## Quick start

Runtime compat patches (vmap-safe masking, collator / checkpoint hooks) are
applied when you construct :class:`opake.transformers.trainer.DPTrainer`, or
when you call :func:`opake.patches.apply_runtime_patches` explicitly (e.g. in
a notebook that uses HF primitives without the trainer).

```python
from opake.patches import apply_runtime_patches, is_runtime_patched
from opake.transformers import DPTrainer

apply_runtime_patches(compat=True)  # global runtime shims — idempotent
trainer = DPTrainer(
    model, args, ...
)  # runtime compat + apply_model_patches on the model

assert is_runtime_patched()
```

## Layout

- **`opake.api.transformers.trainer`** — DPTrainer implementation
  (`_dp_trainer.py`, `_config.py`, `_state.py`, `_optim.py`,
  `_scheduler.py`, `_checkpoint.py`, `_distributed.py`,
  `_performance_kernels.py`, …).
- **`opake.transformers`** / **`opake.transformers.trainer`** — thin
  re-export façades (same pattern as `opake-engine`: `opake.api.*` for
  implementation, `opake.*` for stable imports).
- **`opake.patches.transformers`** — vmap-safe runtime patches and optional
  Triton kernel hooks (see `opake.patches`).
