Skip to content

Remove JAX/Flax - #14169

Merged
DN6 merged 7 commits into
mainfrom
remove-flax
Jul 21, 2026
Merged

Remove JAX/Flax #14169
DN6 merged 7 commits into
mainfrom
remove-flax

Conversation

@DN6

@DN6 DN6 commented Jul 11, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Remove support for JAX/Flax models and pipelines.

Fixes # (issue)

Before submitting

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

DN6 added 3 commits July 11, 2026 13:12
Deletes all Flax models, schedulers, pipelines, and loading utilities,
the from_flax loading path, flax/jax packaging extras, Flax CI filters,
Flax training examples, and Flax content in translated docs.

Hub compatibility is preserved: Flax class names in old model_index.json
files are still stripped to their PyTorch equivalents, and *.msgpack
files in repos are still ignored during download.
Flax-saved checkpoint metadata is no longer recognized: class names like
FlaxStableDiffusionPipeline in model_index.json now fail to resolve
instead of being remapped to their PyTorch equivalents. *.msgpack files
in hub repos are still ignored during download.
The example scripts are standalone and still work with diffusers<=0.39.x.
A warning note is added to each Flax README section pointing out the
version requirement now that the library itself no longer ships Flax.
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@DN6 DN6 mentioned this pull request Jul 13, 2026
@DN6
DN6 requested review from sayakpaul and yiyixuxu July 16, 2026 16:45

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think we're quite close to merge.


if hf_quantizer is not None:
hf_quantizer.validate_environment(torch_dtype=torch_dtype, from_flax=from_flax, device_map=device_map)
hf_quantizer.validate_environment(torch_dtype=torch_dtype, device_map=device_map)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also remove the argument from_flax from the validate_environment() method?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The base class just accepts args and kwargs.

def validate_environment(self, *args, **kwargs):

def test_stable_diffusion_no_safety_checker(self):
pipe = StableDiffusionPipeline.from_pretrained(
"hf-internal-testing/tiny-stable-diffusion-lms-pipe", safety_checker=None
"hf-internal-testing/tiny-stable-diffusion-torch", safety_checker=None

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this test getting affected?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo id uses Flax objects, so these tests fail since we no longer support loading/parsing these objects.

In this particular test, we are loading the torch weights even though there are Flax objects defined in the config.
https://huggingface.co/hf-internal-testing/tiny-stable-diffusion-lms-pipe/blob/main/unet/config.json

The part of the code that allows loading in this way involves stripping out the "Flax" prefix from the model class names. This is no longer supported. So we point to a repo id with proper torch objects.

assert final_tokenizer_size == orig_tokenizer_size
assert final_emb_size == orig_emb_size

def test_download_ignore_files(self):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change doesn't look relevant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The repo id : hf-internal-testing/tiny-stable-diffusion-pipe-ignore-files uses Flax objects in the config files.

However, when looking through the code, it seems that _ignore_files is not properly applied anyway. We download based on allow_patterns and ignore_patterns, and the way these are derived can lead to situations where ignore_files is omitted entirely.

Reproducer:

import os, json
from huggingface_hub import hf_hub_download
from diffusers import DiffusionPipeline

repo = "hf-internal-testing/tiny-stable-diffusion-pipe-ignore-files"

# The repo's model_index.json explicitly asks the downloader to skip these:
ignored = json.load(open(hf_hub_download(repo, "model_index.json")))["_ignore_files"]
# -> ['vae/diffusion_pytorch_model.bin', 'text_encoder/config.json']

folder = DiffusionPipeline.download(repo)
present = {
    os.path.relpath(os.path.join(r, f), folder)
    for r, _, fs in os.walk(folder) for f in fs
}

for f in ignored:
    assert f not in present, f"{f} was listed in _ignore_files but downloaded anyway"

Also searching across all public repos, we don't see this field included anywhere.
https://huggingface.co/search/full-text?q=_ignore_files

So I think we can safely remove since it doesn't seem to be effective.

@sayakpaul sayakpaul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's go!

@DN6

DN6 commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator Author

Failing test is unrelated.

@DN6
DN6 merged commit 80bfe77 into main Jul 21, 2026
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants