Skip to content

performance(weight-free): link deferred weights from Hugging Face checkpoints#643

Draft
rebel-jongho wants to merge 2 commits into
devfrom
jongho/wf-temp2
Draft

performance(weight-free): link deferred weights from Hugging Face checkpoints#643
rebel-jongho wants to merge 2 commits into
devfrom
jongho/wf-temp2

Conversation

@rebel-jongho

@rebel-jongho rebel-jongho commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Description

Type of Change

  • New feature (non-breaking change which adds functionality)

Changes Overview

This wires weight-free compilation into optimum-rbln. Exporting with weight_free=True excludes the state dict from the compiled artifact and streams the weights in from the original Hugging Face checkpoint at load time.

  • New weight_source utility (src/optimum/rbln/utils/weight_source.py): maps the compiler's weight names to the original checkpoint keys via tensor identity (data_ptr, storage offset, numel, dtype, shape, stride). Tensors that exist in the HF checkpoint are streamed from safetensors per pool-window; only tensors generated or derived during compilation are persisted separately to rbln_generated_tensors.safetensors next to the artifact.
  • Runtime weight injection (modeling_decoderonly.py): at load, each runtime's required windows come from runtime.weight_load_plan(), and runtime.load_weight_window(chunk, graph_ids) fills only those windows.
  • Fresh-load support: the saved weight_source metadata (model_id, revision, subfolder, variant) drives a snapshot_download, so weights can be re-fetched from the original checkpoint independently of the export session.
  • Config fields (configuration_utils.py): adds weight_free, weight_source, weight_name_map, and generated_weight_map to RBLNModelConfig.
  • Decoder-only wiring (modeling_base.py, modeling_decoderonly.py): the base class carries _supports_weight_free=False plus export/load hooks; decoder-only opts in with _supports_weight_free=True. Requesting weight_free on an unsupported model is rejected clearly, and quantization/LoRA combinations are guarded as not-yet-supported.
  • Example (examples/text-generation/run_qwen3.py): exercises the weight-free path end to end.

Motivation and Context

A compiled artifact is dominated by its weights, which makes distribution and transfer expensive. Weight-free separates the weights from the artifact and injects them from the original checkpoint at load time, shrinking the artifact dramatically. For example, Qwen3-0.6B is a 2.47 GB baked artifact but only a 33.8 MB weight-free artifact plus a 264 KB generated-tensor file.

This feature depends on the runtime APIs (weight_load_plan / load_weight_window) and the state-dict-excluding compile path introduced by the rebel-compiler weight-key PR (RBLN-SW/rebel_compiler#11982), so it should be validated and merged together with that compiler PR.

Validation

  • tests/test_weight_source.py (new, 212 lines): unit-covers identity mapping, generated-tensor persistence, window streaming, and the fresh-load path.
  • e2e (Qwen3-0.6B): confirmed the state dict is actually excluded from the artifact (.rbln 33.8 MB + 264 KB generated tensors vs. 2.47 GB baked, 3.0 GB raw weights); both the export-session generation and a fresh-load generation produce coherent, deterministic output.

Related Issues

  • Depends on: RBLN-SW/rebel_compiler#11982 (weight-key / weight-free compiler support)

Conventional commit

performance(weight-free): link deferred weights from Hugging Face checkpoints

rebel-jongho and others added 2 commits July 24, 2026 03:43
…e license header

- test_weight_source: remove the two overlapping tests (generated-state save
  round-trip already covered by the artifact integration test; base-config
  storage already covered by the serialization test) and prune now-unused imports.
- Trim over-length comments in modeling.py and the run_qwen3 example.
- Replace the truncated license header in weight_source.py with the full
  Apache 2.0 header used across the package.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant