kernels 0.4.0__tar.gz → 0.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kernels
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Download compute kernels
5
5
  Author-email: OlivierDehaene <olivier@huggingface.co>, Daniel de Kok <daniel@huggingface.co>, David Holtz <david@huggingface.co>, Nicolas Patry <nicolas@huggingface.co>
6
6
  Requires-Python: >=3.9
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kernels"
3
- version = "0.4.0"
3
+ version = "0.4.2"
4
4
  description = "Download compute kernels"
5
5
  authors = [
6
6
  { name = "OlivierDehaene", email = "olivier@huggingface.co" },
@@ -4,6 +4,7 @@ from kernels.layer import (
4
4
  register_kernel_mapping,
5
5
  replace_kernel_forward_from_hub,
6
6
  use_kernel_forward_from_hub,
7
+ use_kernel_mapping,
7
8
  )
8
9
  from kernels.utils import (
9
10
  get_kernel,
@@ -18,6 +19,7 @@ __all__ = [
18
19
  "load_kernel",
19
20
  "install_kernel",
20
21
  "use_kernel_forward_from_hub",
22
+ "use_kernel_mapping",
21
23
  "register_kernel_mapping",
22
24
  "replace_kernel_forward_from_hub",
23
25
  "LayerRepository",
@@ -1,4 +1,5 @@
1
1
  import inspect
2
+ import warnings
2
3
  from contextvars import ContextVar
3
4
  from copy import deepcopy
4
5
  from dataclasses import dataclass, field
@@ -132,6 +133,12 @@ def replace_kernel_forward_from_hub(cls, layer_name: str, *, use_fallback: bool
132
133
  def forward(self, x, *args, **kwargs):
133
134
  kernel = _KERNEL_MAPPING.get().get(layer_name)
134
135
  if kernel is None:
136
+ warnings.warn(
137
+ "\n"
138
+ f"No kernel mapping found for layer `{layer_name}`. "
139
+ f"Check if the layer name matches one of the kernels in the mapping or add the kernel "
140
+ f"you want to use to the mapping. Defaulting to original forward implementation."
141
+ )
135
142
  if not use_fallback:
136
143
  raise ValueError(f"No layer mapping for `{layer_name}`")
137
144
  return fallback_forward(self, x, *args, **kwargs)
@@ -23,18 +23,21 @@ CACHE_DIR: Optional[str] = os.environ.get("HF_KERNELS_CACHE", None)
23
23
  def build_variant() -> str:
24
24
  import torch
25
25
 
26
- if torch.version.cuda is None:
27
- raise AssertionError(
28
- "This kernel requires CUDA to be installed. Torch was not compiled with CUDA enabled."
29
- )
26
+ if torch.version.cuda is not None:
27
+ cuda_version = parse(torch.version.cuda)
28
+ compute_framework = f"cu{cuda_version.major}{cuda_version.minor}"
29
+ elif torch.version.hip is not None:
30
+ rocm_version = parse(torch.version.hip.split("-")[0])
31
+ compute_framework = f"rocm{rocm_version.major}{rocm_version.minor}"
32
+ else:
33
+ raise AssertionError("Torch was not compiled with CUDA or ROCm enabled.")
30
34
 
31
35
  torch_version = parse(torch.__version__)
32
- cuda_version = parse(torch.version.cuda)
33
36
  cxxabi = "cxx11" if torch.compiled_with_cxx11_abi() else "cxx98"
34
37
  cpu = platform.machine()
35
38
  os = platform.system().lower()
36
39
 
37
- return f"torch{torch_version.major}{torch_version.minor}-{cxxabi}-cu{cuda_version.major}{cuda_version.minor}-{cpu}-{os}"
40
+ return f"torch{torch_version.major}{torch_version.minor}-{cxxabi}-{compute_framework}-{cpu}-{os}"
38
41
 
39
42
 
40
43
  def universal_build_variant() -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kernels
3
- Version: 0.4.0
3
+ Version: 0.4.2
4
4
  Summary: Download compute kernels
5
5
  Author-email: OlivierDehaene <olivier@huggingface.co>, Daniel de Kok <daniel@huggingface.co>, David Holtz <david@huggingface.co>, Nicolas Patry <nicolas@huggingface.co>
6
6
  Requires-Python: >=3.9
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes