Text Generation
PEFT
Safetensors
GGUF
granite
uno
speculative-decoding
block-diffusion
lora
oflm
openflowlm
npu2
q4nx
conversational
Instructions to use Cyronius/granite-4.2-3b-uno with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Cyronius/granite-4.2-3b-uno with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("ibm-granite/granite-4.2-3b") model = PeftModel.from_pretrained(base_model, "Cyronius/granite-4.2-3b-uno") - Notebooks
- Google Colab
- Kaggle
Download code/training/checkpointing.py from Cyronius/granite-4.2-3b-uno: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/Cyronius/granite-4.2-3b-uno/resolve/main/code/training/checkpointing.py
- Command line
-
hf download hf://Cyronius/granite-4.2-3b-uno/code/training/checkpointing.py
-
curl -L -o checkpointing.py https://huggingface.co/Cyronius/granite-4.2-3b-uno/resolve/main/code/training/checkpointing.py
2.01 kB
| # Portions adapted from LlamaFactory, Copyright 2025 the LlamaFactory team, | |
| # under the Apache License 2.0. | |
| from __future__ import annotations | |
| from functools import WRAPPER_ASSIGNMENTS, partial, wraps | |
| from types import MethodType | |
| import torch | |
| def _checkpoint_trainable_layers(checkpoint_function): | |
| """Checkpoint only modules with trainable weights and seed their input grad.""" | |
| def wrapped(function, *args, **kwargs): | |
| module = function.func.__self__ if isinstance(function, partial) else function.__self__ | |
| if any(parameter.requires_grad for parameter in module.parameters()): | |
| for argument in args: | |
| if torch.is_tensor(argument) and torch.is_floating_point(argument): | |
| argument.requires_grad_(True) | |
| break | |
| return checkpoint_function(function, *args, **kwargs) | |
| return function(*args, **kwargs) | |
| return wrapped | |
| def _enable_gradient_checkpointing(self, gradient_checkpointing_kwargs=None): | |
| from torch.utils.checkpoint import checkpoint | |
| if not self.supports_gradient_checkpointing: | |
| raise ValueError(f"{self.__class__.__name__} does not support checkpointing.") | |
| if gradient_checkpointing_kwargs is None: | |
| gradient_checkpointing_kwargs = {"use_reentrant": True} | |
| checkpoint_function = _checkpoint_trainable_layers( | |
| partial(checkpoint, **gradient_checkpointing_kwargs) | |
| ) | |
| self._set_gradient_checkpointing( | |
| enable=True, gradient_checkpointing_func=checkpoint_function | |
| ) | |
| def configure_gradient_checkpointing(model) -> None: | |
| """Install the proven LoRA-aware checkpointing behavior before PEFT wrapping.""" | |
| model.gradient_checkpointing_enable = MethodType( | |
| _enable_gradient_checkpointing, model | |
| ) | |
| model.gradient_checkpointing_enable( | |
| gradient_checkpointing_kwargs={"use_reentrant": True} | |
| ) | |
| model.config.use_cache = False | |