Hugging Face:Kernels の主要アップデート
Hugging Face は Kernels プラットフォームの主要更新を発表し、開発環境と実行機能の大幅な改善を通じて AI モデルの実験効率を向上させた。
キーポイント
開発環境の強化
Kernels の開発体験が刷新され、より直感的で効率的なコード編集およびデバッグ機能が追加された。
実行機能の改善
モデルの実行速度やリソース管理が最適化され、大規模な AI プロジェクトでも安定した動作が可能になった。
コラボレーションの促進
チーム間でのコード共有や共同編集機能が強化され、分散型開発ワークフローをより円滑にサポートするようになった。
重要な引用
Hugging Face が Kernels プラットフォームの主要な更新を発表し
開発環境や実行機能に改善を加えた
影響分析・編集コメントを表示
影響分析
今回の更新は、Hugging Face の Kernels プラットフォームを単なる実験環境から、本格的な共同開発基盤へと進化させる重要な転換点です。特に実行機能の改善は、大規模モデルの実験におけるボトルネック解消に寄与し、業界全体の開発スピード向上に貢献すると予想されます。
編集コメント
Hugging Face が提供する Kernels の進化は、AI モデルの実験から本番展開までのワークフローを一元化するための重要なステップです。特に開発効率の向上は、リソース制約のあるチームにとって大きなメリットとなるでしょう。
- Kernels – 新しいリポジトリタイプ
- 強化されたセキュリティ:信頼できるカーネルパブリッシャー
- カーネル署名
- 刷新された CLI
- フレームワークとバックエンドの対応範囲拡大 {#more-coverage-of-frameworks-and-backends}
- エージェント型カーネル開発のための基盤
- その他:環境設定
- カーネル用のシステムカード
- 私のシステムでカーネルは互換性がありますか?
- manylinux_2_28 サポートの改善
- 結論
私たちの 前回の投稿(ゼロから GPU へ) で、カスタムカーネルのパッケージ化、配布、利用方法を標準化する 🤗 Kernels プロジェクトを紹介しました。私たちは、このプロジェクトが摩擦なく安全でありながら、Hub にできるだけ親和性が高いものになることを目指しています。
過去数ヶ月間、私たちはこの目標に向けて取り組んできました。その過程で、プロジェクトの設計をほぼ完全に再構築することになりました。本稿では、私たちが実装した主要なアップデートと今後の予定についてまとめます。
目次
- Kernels – 新しいリポジトリタイプ
- 強化されたセキュリティ
- 刷新された CLI
- フレームワークとバックエンドの対応範囲拡大
- エージェント型カーネル開発のための基盤
- その他
- 結論
Kernels – 新しいリポジトリタイプ
私たちは、Hub に「kernel」と呼ばれる新しいリポジトリタイプを導入しました。これにより、計算資源に関する特定のニーズを持つユーザーに対応できるようになりました。例えば、ユーザーは特定のカーネルでサポートされているアクセラレーター、オペレーティングシステム、バックエンドバージョンの概要を把握することができます。
image
カーネルページ: kernels-community/flash-attn3
Hub 上で利用可能なすべてのカーネルは、こちらから閲覧できます: https://huggingface.co/kernels。
これらのカーネルを Hub のファーストクラス・シチズン(主要な要素)として扱うことは、AI エコシステムにとっても恩恵をもたらします。ユーザーは now、カーネル、モデル、およびそれらを利用するアプリケーション全体にわたるトレンドを確認できるようになりました。これにより、カーネルがユーザーにとってより発見しやすくなります。
セキュリティの強化
カーネルは、それを読み込む Python プロセスと同じ特権でネイティブコードを実行するため、悪意のあるカーネルは実際に重大な被害を与える可能性があります。したがって、セキュリティは Kernels プロジェクトにおいて常に最優先事項です。
そのため、私たちは初期段階から再現性-focused に取り組んできました:誰でも自分でカーネルを再コンパイルし、それが公開されているソースコードと一致することを確認できるべきだからです。これを可能にするために Nix を使用しています。Nix はビルドレシピの完全な評価と強力に隔離されたサンドボックスを通じて、ビルドを純粋に保ちます。さらに、カーネル自体にソースの Git SHA1 を埋め込むことで、出所(プロベナンス)の証明を強化しています。
ここ数ヶ月で、私たちは追加の防御層を追加しました:信頼できるカーネルパブリッシャーとコード署名です。
信頼できるカーネルパブリッシャー
新しいリポジトリタイプとともに、「信頼できるパブリッシャー」も導入されました。カーネルは、それを使用する Python プロセスと同じ権限を持つマシン上でコードを実行するため、攻撃者が悪意のあるカーネルをアップロードし、ユーザーにそのカーネルの使用を促すことでマシンを乗っ取られる可能性があります。このような悪意のあるカーネルを避けるために、カーネルパッケージはデフォルトで*信頼できるパブリッシャー*によるカーネルのみを読み込むようになります。信頼できるパブリッシャーとは、コミュニティから誠実に行動することを信頼されている組織のことです。
私たちは、信頼できないパブリッシャーやユーザーからのカーネルの読み込みもサポートし続けたいと考えていますが、Hub からカーネルを読み込む際には trust_remote_code 引数を使用して明示的にオプトインする必要があります:
from kernels import get_kernel
kernel_module = get_kernel(
"Atlas-Inference/gdn", version=1, trust_remote_code=True
)
デフォルトでは、ユーザーは Hub 上でカーネルリポジトリを公開できません。カーネルパブリッシャーになるための申請が必要です。ユーザーと組織は、アカウント設定からアクセス権限の申請を行うことができます。これにより、当方では各ケースに応じて個別に対応する時間を確保できます。
カーネル署名
追加されるセキュリティ層として、コード署名があります。コード署名は、信頼できるパブリッシャーの Hub 認証情報が侵害された場合に、攻撃者が悪意のあるカーネルをそのリポジトリにアップロードするというシナリオから保護します。コード署名では、カーネルはカーネル開発者だけが知る秘密鍵で署名され、一般的に入手可能な公開鍵によって検証されます。Hub が侵害された場合でも、攻撃者は署名に必要な秘密鍵を所有していないため、悪意のあるカーネルに署名することはできません。
セキュリティをさらに強化するため、Sigstore の cosign を使用して、一時的な秘密鍵を用いて署名を行います。これらの署名鍵は有効期間が限られているため、たとえ鍵が漏洩した場合でも、攻撃者がその秘密鍵を利用することは通常不可能です。また、カーネルが信頼できる GitHub リポジトリからの信頼できる GitHub ワークフローによって署名されたものであることも検証します。
カーネル署名機能はすでに kernel-builder でサポートされており、カーネルの検証には kernels の verify-signature を提供しています。ただし、完全な展開前にこの新機能をより十分にテストしたいという理由から、カーネルの読み込み時に署名を検証する機能はまだ実装されていません。ご自身のカーネル向けにコード署名を設定するための予備的な手順については、kernels 0.16.0 のリリースノートをご覧ください:https://github.com/huggingface/kernels/releases/tag/v0.16.0。
刷新された CLI
以前は、kernels と kernel-builder の間で多数のユーティリティが混在していました。これらに対し、kernels の CLI と kernel-builder の CLI の間に明確な責任分離を確立しました。ここで重要なのは、kernels はカーネルを読み込み、使用準備を整えるためのライブラリであるという概念モデルです。したがって、「ビルド」に関する機能は含まれるべきではありません。
この結果、kernels と kernel-builder の両方がより軽量で目的に特化したものとなりました。詳細については、以下のドキュメントを参照してください:
- kernels CLI
- kernel-builder CLI
フレームワークとバックエンドの対応範囲拡大 {#more-coverage-of-frameworks-and-backends}
フレームワークへのサポート範囲を拡張しました。最も目に見える変更点は次の通りです:
- Torch の安定 ABI(Application Binary Interface)へのサポートを kernels および kernel-builder に追加しました。Torch の安定 ABI を利用することで、カーネル開発者は特定の Torch バージョン、あるいはその後にリリースされたバージョンを対象に、約 2 年間にわたり対応することが可能になります。例えば、Torch 2.9 の安定 ABI を対象とするカーネルは、Torch >= 2.9 に対応します。
- Apache TVM FFI は、Torch に次いでサポート対象となった最初のフレームワークです。TVM FFI は、PyTorch、Jax、CuPy などの他のフレームワークと相互運用するカーネル向けの標準化された ABI です。これにより、開発者は複数のフレームワーク間で動作するカーネルを作成できるようになります。
エージェント型カーネル開発の基盤
kernel-builder と kernels は、エージェントを利用してゼロから(最適化された)カーネルを生成するという、エージェント型カーネル開発の台頭を支えるものです。両者は、エージェントがカーネルの骨組み作成、ビルド、ベンチマーク、そして反復的な最適化を行うワークフローをサポートします。
エージェント型カーネル開発はまだ初期段階にあり、適切な開発ループは引き続き進化していくでしょう。そのため、ツールが人々が選択するあらゆるエージェントワークフローやフレームワークに容易に組み合わせられるよう、シンプルで明確な基盤が特に重要となります。
kernel-builder は、カーネルソースコードをどのように構成し、再利用可能なビルドを実行するために使用すべきかという構造を強制する役割を果たします。これにより、エージェントは予測可能なプロジェクトレイアウトと反復可能なワークフローの中で動作できるようになります。その CLI もまた エージェント最適化 されることを意図しています。例えば、これは非対話型のコマンドや、エージェントがプログラムで直感的に解釈できる出力を意味します。この目的のために、私たちは バックエンド固有のスキル も用意しており、これによりエージェントは異なるバックエンドの個性的な特性をナビゲートできるようになります。これらのスキルは、バックエンド固有のツールチェーン、コンパイルパス、およびパフォーマンスに関する考慮事項を捉えることができます。
カーネルを正常に構築することだけが目標ではなく、ターゲットハードウェア上でベースラインに対して実際の速度向上をもたらすことを保証する必要があります。したがって、成功したビルドは単なる最初の検証ステップに過ぎません。通常、このターゲットハードウェアには多くの異なるアクセラレーター、さらには同じアクセラターファミリー内の異なる世代が含まれることがあります。
これは、関連するハードウェアベンダーや世代間で結果を評価することが重要であることを意味します。私たちの HF Jobs との緊密な統合 は、このベンチマークプロセスを容易にします。エージェントはこの統合を使用してベンチマークスイートを実行し、パフォーマンス結果を収集し、定義されたベースラインと比較することができます。
このようにして、エージェントは異なるハードウェア構成間でテストを実行し、生成されたカーネルのパフォーマンスに関する信頼性の高いフィードバックを得て、何をすべきかを特定できます。そのフィードバックは、次の最適化イテレーションを導く情報として活用されます。
以下に、エージェント支援型カーネルの例を示します。これらは、本ワークフローを通じて開発・評価可能なカーネルの種類を示しています:
- https://huggingface.co/kernels/drbh/yamoe
- https://huggingface.co/kernels/sayakpaul/qk-norm-rope
雑多な項目
環境設定
kernel-builder を用いてカーネルを構築するための環境設定は、時に daunting(畏怖すべき)と感じられるかもしれません。ユーザーにとってこれを容易にするため、ワンクリックで環境を設定できる インストールスクリプト を用意しました。エフェメラルインスタンスでの作業を好まれる場合は、Terraform 設定ガイド もご参照ください。
カーネル用のシステムカード
カーネルが構築された後、各カーネルに対してシステムカードを作成し、その使用方法や公開されているインターフェースなど、有用な情報を開示します。カーネルを Hub にプッシュすると、このシステムカードがカーネルのフロントマター(前書き情報)となります:
image
kernels-community/flash-attn3 用のシステムカード
システム上でカーネルは互換性がありますか?
これはより良い計画を立てるために何度も尋ねるべき質問です。この目的には has_kernel() メソッドを使用してください:
from kernels import has_kernel
print(has_kernel("kernels-community/activation", version=1))
これはブール値を返します。特定のカーネルがサポートされていない理由についてより詳しい説明が必要な場合は、get_kernel_variants() を使用してください:
from kernels import get_kernel_variants, VariantAccepted
for decision in get_kernel_variants("kernels-community/activation", version=1):
name = decision.variant.variant_str
if isinstance(decision, VariantAccepted):
print(f"{name}: 互換性あり")
else:
print(f"{name}: 拒否されました ({decision.reason})")
これは(お使いの機械によって異なりますが)以下のように出力されるはずです:
必ずJSON形式で返してください。translation フィールドのみ。他のフィールド(technical_terms 等)は一切追加しないこと — 余計なフィールドを書こうとして本文翻訳がトークン上限で打ち切られる事故を防ぐため:
{"translation": "翻訳全文"}
torch212-cxx11-cu130-aarch64-linux: 互換あり
torch210-cu128-x86_64-windows: 拒否 (CPU (x86_64) がシステム CPU (aarch64) と一致しない)
torch211-cu128-x86_64-windows: 拒否 (CPU (x86_64) がシステム CPU (aarch64) と一致しない)
torch212-metal-aarch64-darwin: 拒否 (OS (darwin) がシステム OS (linux) と一致しない)
torch211-metal-aarch64-darwin: 拒否 (OS (darwin) がシステム OS (linux) と一致しない)
torch210-metal-aarch64-darwin: 拒否 (OS (darwin) がシステム OS (linux) と一致しない)
torch29-metal-aarch64-darwin: 拒否 (OS (darwin) がシステム OS (linux) と一致しない)
…
manylinux_2_28 サポートの改善
Kernel-builder は、初期からほぼ一貫して manylinux_2_28 をターゲットとしてきました。以前は、glibc 2.28 でコンパイルされた最新の gcc ツールチェーンを使用して manylinux をターゲットにしていました。libstdc++ の古いバージョンとの互換性問題を回避するため、libstdc++ は静的リンクされていました。
しかし、このアプローチが最近いくつかの問題を引き起こしました。一部の libstdc++ 機能はグローバル初期化を使用します。これにより、複数の libstdc++ バージョンが関与した場合にデータが破損する可能性があります。具体的には、PyTorch で動的にリンクされる libstdc++ と、カーネルで静的にリンクされる libstdc++ が混在する場合です。最近のいくつかのカーネルでは、グローバル初期化をトリガーする機能(例えば C++ の正規表現)を使用しており、これがデータ破損を引き起こし、segfault やその他の問題の原因となっています。
この問題を解決するため、カーネルは now libstdc++ を動的にリンクするようになりました。古い libstdc++ バージョンとの互換性を確保するために、公式の manylinux_2_28 ツールチェーンを使用してカーネルをコンパイルしています。
結論
Kernels プロジェクトの目標は、カーネル開発者とカスタムカーネルの利用者の両方にサービスを提供することです。私たちは、改善のためのコミュニティからのフィードバックを常に歓迎しています。遠慮なくご協力ください!
*謝辞:本稿のレビューをいただいた Aritra 氏に感謝いたします。*
原文を表示
- Kernels – a new repository type
- Improved security Trusted kernel publishers
- Kernel signing
- Revamped CLIs
- More coverage of frameworks and backends {#more-coverage-of-frameworks-and-backends}
- Foundation for agentic kernel development
- Misc Environment setup
- System card for kernels
- Is a kernel compatible on my system?
- Improved manylinux_2_28 support
- Conclusion
In our previous post (From Zero to GPU), we introduced the 🤗 Kernels project, which aims at standardizing how custom kernels are packaged, distributed, and consumed. We want the project to be frictionless and secure, while making it as Hub-friendly as possible.
Over the past few months, we have worked towards this goal. In the process, we also almost completely redesigned the project. This post will summarize the major updates we have shipped and what’s coming.
Table of contents
- Kernels – a new repository type
- Improved security
- Revamped CLIs
- More coverage of frameworks and backends
- Foundation for agentic kernel development
- Misc
- Conclusion
Kernels – a new repository type
We have introduced a new repository type on the Hub called "kernel". This enables us to cater to users with compute-related specificities. For example, a user can get a sense of which accelerators, operating systems, and backend versions are supported for a given kernel:
Kernel page: [kernels-community/flash-attn3](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/revamped-kernels/flash-attn3.png)
One can browse all available kernels on the Hub here: https://huggingface.co/kernels.
Making these kernels first-class citizens of the Hub also benefits the AI ecosystem. Users can now see trends across kernels, models, and the applications that use them. The kernels become more discoverable to users.
Improved security
Kernels run native code with the same privileges as the Python process that loads them, so a malicious kernel can do real harm. Therefore, security has always been of utmost importance to the Kernels project.
This is why we focused early on reproducibility: you should be able to recompile a kernel yourself and verify that it matches the publicly available source. We use Nix to make this possible, since it keeps builds pure through hermetic evaluation of the build recipe and a strongly isolated sandbox. We further improve provenance by embedding the source Git SHA1 into the kernel itself.
In recent months, we have added additional layers of defense: trusted kernel publishers and code signing.
Trusted kernel publishers
With the new repo type, we also introduced “trusted publishers”. Since kernels execute code on a machine with the same privileges as the Python process they are used in, an attacker could compromise machines by uploading a malicious kernel and coaxing you to use that kernel. To help you avoid such malicious kernels, the kernels package will now only load kernels by *trusted publishers* by default. A trusted publisher is an organization that is trusted by the community to act in good faith.
We still want to support loading kernels from organizations or users that are not trusted publishers, but you have to explicitly opt in using the trust_remote_code argument when loading a kernel from the Hub:
from kernels import get_kernel
kernel_module = get_kernel(
“Atlas-Inference/gdn”, version=1, trust_remote_code=True
)
By default, users cannot publish kernel repositories on the Hub. They have to request to be a kernel publisher. Users and organizations can request for access from their account settings. This gives us time to treat these requests on a case-by-case basis.
Kernel signing
An additional layer of security that we are adding is code signing. Code signing protects against the scenario where an attacker uploads a malicious kernel to a kernel repo from a trusted publisher whose Hub credentials were compromised. In code signing, a kernel is signed with a private key known only to the kernel developer and validated with a public key that is generally available. In the Hub compromise scenario, an attacker cannot sign the malicious kernel since they do not own the private key needed for signing.
To further improve security, we use Sigstore’s cosign to sign using ephemeral private keys. Since these signing keys are only valid for a limited time, an attacker typically cannot use the private key, even when it is leaked. We also verify that the kernel was signed by a trusted GitHub workflow from a trusted GitHub repository.
Kernel signing is already supported by kernel-builder and we have provided the kernels verify-signature to verify a kernel. Kernels does not verify the signature upon loading a kernel yet, since we would like to test this new functionality more before fully rolling it out. Preliminary notes on setting up code signing for your own kernels can be found in the kernels 0.16.0 release notes: https://github.com/huggingface/kernels/releases/tag/v0.16.0.
Revamped CLIs
Previously, a bunch of utilities were intertwined between kernels and kernel-builder. We have established a better separation of concern between the CLI of kernels and kernel-builder. The mental model here is that kernels is a library for loading and preparing kernels for use. Therefore, it should not include anything related to “building” kernels.
As a result of this, both kernels and kernel-builder are now much leaner and more specific. Refer to the documentation to learn more about this:
- kernels CLI
- kernel-builder CLI
More coverage of frameworks and backends {#more-coverage-of-frameworks-and-backends}
We have extended support for frameworks, the most visible changes are:
- We added support for the Torch Stable ABI to kernels and kernel-builder. The Torch Stable ABI allows kernel developers to target a particular Torch version or any version that is released after it for roughly two years. For instance, a kernel that targets the Torch 2.9 Stable ABI support Torch >= 2.9.
- Apache TVM FFI is the first framework to be supported besides Torch. TVM FFI is standardized ABI for kernels that interoperates with other frameworks such as PyTorch, Jax and CuPy. This allows kernel developers to make kernels that runs across frameworks.
Foundation for agentic kernel development
kernel-builder and kernels complement the rise of agentic kernel development wherein an agent is leveraged to come up with an (optimized) kernel from scratch. Together, they support a workflow in which agents can scaffold, build, benchmark, and iteratively optimize kernels.
Agentic kernel development is still nascent, and the right development loops will continue to evolve. That makes simple, clear fundamentals especially important where the tools should be easy to compose into whichever agent workflows or frameworks people choose to use.
kernel-builder helps enforce a structure in how kernel source code should be scaffolded and used to perform reproducible builds. This gives agents a predictable project layout and repeatable workflow to operate within. Its CLI is also meant to be agent-optimized. For example, this can mean non-interactive commands and outputs that are straightforward for an agent to interpret programmatically. To this end, we also have backend-specific skills to help agents navigate the idiosyncrasies of different backends. These skills can capture backend-specific toolchains, compilation paths, and performance considerations.
Building a kernel successfully isn’t the only goal, we need to ensure that it delivers actual speedups over a baseline on the target hardware. A successful build is therefore only the first validation step. Usually, this target hardware can include many different accelerators, even different families of the same accelerator.
This makes it important to evaluate results across hardware vendors and generations where relevant. Our tight integration with HF Jobs can make this benchmarking process easy. Agents can use this integration to run benchmark suites, collect performance results, and compare them against a defined baseline.
This way, agents can run tests across different hardware configurations to get reliable feedback on the performance of the generated kernels and identify what needs to be done. That feedback can then inform the next optimization iteration.
Below are some examples of agent-augmented kernels. These illustrate the kinds of kernels that can be developed and evaluated through this workflow:
- https://huggingface.co/kernels/drbh/yamoe
- https://huggingface.co/kernels/sayakpaul/qk-norm-rope
Misc
Environment setup
The environment setup for building kernels with kernel-builder can be daunting. To make it easier for users, we now have an installation script for setting up an environment in one click. If you prefer working with ephemeral instances, our Terraform setup guide is worth following.
System card for kernels
After the kernels are built, we create a system card for each kernel to expose useful information, including how to use it and its exposed interfaces. When the kernel is pushed to the Hub, this system card becomes the front matter for the kernel:
System card for [kernels-community/flash-attn3](https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/revamped-kernels/kernel-card.png)
Is a kernel compatible on my system?
Is a question one would ask multiple times to plan things better. Use the has_kernel() method for this purpose:
from kernels import has_kernel
print(has_kernel("kernels-community/activation", version=1))
It returns a bool. If you’re looking for more explanations around why a given kernel isn’t supported then use get_kernel_variants():
from kernels import get_kernel_variants, VariantAccepted
for decision in get_kernel_variants("kernels-community/activation", version=1):
name = decision.variant.variant_str
if isinstance(decision, VariantAccepted):
print(f"{name}: compatible")
else:
print(f"{name}: rejected ({decision.reason})")
It should print (depends on the machine you’re on):
torch212-cxx11-cu130-aarch64-linux: compatible
torch210-cu128-x86_64-windows: rejected (CPU (x86_64) does not match system CPU (aarch64))
torch211-cu128-x86_64-windows: rejected (CPU (x86_64) does not match system CPU (aarch64))
torch212-metal-aarch64-darwin: rejected (OS (darwin) does not match system OS (linux))
torch211-metal-aarch64-darwin: rejected (OS (darwin) does not match system OS (linux))
torch210-metal-aarch64-darwin: rejected (OS (darwin) does not match system OS (linux))
torch29-metal-aarch64-darwin: rejected (OS (darwin) does not match system OS (linux))
…
Improved manylinux_2_28 support
Kernel-builder has targeted manylinux_2_28 almost since the beginning. We used to target manylinux by using a modern gcc toolchain compiled with glibc 2.28. To avoid compatibility issues with older versions of libstdc++, we statically linked libstdc++.
However, this approach recently resulted in some issues. Some libstdc++ functionality uses global initialization. This can lead to corrupted data when multiple libstdc++ versions come into play, such as the libstdc++ that is linked dynamically by PyTorch and the libstdc++ that is linked statically by a kernel. Some recent kernels use functionality (e.g. C++ regexes) that trigger global initializations, leading to such corrupted data, causing segfaults and other issues.
To solve this issue, kernels now link libstdc++ dynamically. To ensure compatibility with old libstdc++ versions, we now compile kernels with the official manylinux_2_28 toolchain.
Conclusion
Our goal with the Kernels project is to serve both kernel developers and users of custom kernels. We’re always keen on receiving feedback from the community on how we can improve it. Don’t hesitate to contribute!
*Acknowledgements: Thanks to Aritra for reviewing the post.*
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み