Skip to content

Instantly share code, notes, and snippets.

View andrewor14's full-sized avatar

andrewor14

View GitHub Profile
from unsloth import FastLanguageModel
import torch
from torchao.quantization import Int4WeightOnlyConfig
from transformers import AutoModelForCausalLM, TextStreamer, TorchAoConfig
qat_scheme = "int4"
save_output_path = "/tmp/unsloth_model"
max_seq_length = 2048
@andrewor14
andrewor14 / gist:378a86485e2bc167f851bfd648625b70
Created October 2, 2025 23:33
UnslothGRPOTrainer excerpt
class _UnslothGRPOTrainer(Trainer):
...
def _sync_fsdp1_params_to_vllm(self, module: nn.Module, prefix: str = "", visited=None):
"""Memory-efficient post-order traversal of FSDP modules to extract full parameters and sync with vLLM."""
# For FSDP1, we need to recurse into children and also use summon_full_params
if visited is None:
visited = set()
for child_name, child_module in module.named_children():
child_prefix = f"{prefix}.{child_name}" if prefix else child_name
[rank0]: Traceback (most recent call last):
[rank0]: File "/home/andrewor/local/unsloth-zoo/unsloth_zoo/vllm_utils.py", line 884, in get_state_dict
[rank0]: weight = qweight[dim_offsets[kk] : dim_offsets[kk + 1]]
[rank0]: File "/home/andrewor/local/ao/torchao/utils.py", line 662, in _dispatch__torch_function__
[rank0]: raise e
[rank0]: File "/home/andrewor/local/ao/torchao/utils.py", line 659, in _dispatch__torch_function__
[rank0]: return func(*args, **kwargs)
[rank0]: RuntimeError: Cannot set version_counter for inference tensor
[rank0]: Exception raised from set_version_counter at /pytorch/c10/core/TensorImpl.h:2117 (most recent call first):
[rank0]: C++ CapturedTraceback:
@andrewor14
andrewor14 / gist:5b85119fae46845d07b608d420907423
Created November 11, 2025 20:54
Unsloth FP8 + GRPO test script
# Modeled after https://colab.research.google.com/github/unslothai/notebooks/blob/main/nb/Qwen3_(4B)-GRPO.ipynb
from unsloth import FastLanguageModel
import gc
import os
import re
from datasets import load_dataset, Dataset
from trl import GRPOConfig, GRPOTrainer, SFTConfig, SFTTrainer