Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/transformers/integrations/hub_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,17 @@ class LayerRepository:
def __init__(self, *args, **kwargs):
raise RuntimeError("LayerRepository requires `kernels` to be installed. Run `pip install kernels`.")

def load(self):
raise NotImplementedError("LayerRepository requires `kernels` to be installed. Run `pip install kernels.")
class LocalLayerRepository:
def __init__(self, *args, **kwargs):
raise RuntimeError("LocalLayerRepository requires `kernels` to be installed. Run `pip install kernels`.")

def load(self):
raise NotImplementedError(
"LocalLayerRepository requires `kernels` to be installed. Run `pip install kernels."
)

class FuncRepository:
def __init__(self, *args, **kwargs):
raise RuntimeError("FuncRepository requires `kernels` to be installed. Run `pip install kernels`.")
Expand Down Expand Up @@ -745,10 +752,8 @@ def register_kernel_replacements_and_fusions(
raise ValueError(f"Invalid kernel repo string {repo_str!r} for layer {layer_name!r}")

if kernel_config.use_local_kernel:
package_name = repo_id.rstrip("/").split("/")[-1]
repo = LocalLayerRepository(
repo_path=Path(repo_id),
package_name=package_name,
layer_name=layer_name_in_repo,
)
else:
Expand Down
5 changes: 1 addition & 4 deletions src/transformers/utils/kernel_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,10 @@ def add_to_mapping_local(layer_name, device, repo_name, mode, compatible_mapping
raise ValueError(f"Only cuda, rocm, xpu, npu, neuron and tpu devices supported, got: {device}")
repo_layer_name = repo_name.split(":")[1]
repo_path = repo_name.split(":")[0]
repo_package_name = repo_path.split("/")[-1]
compatible_mapping[layer_name] = {
device: {
mode: LocalLayerRepository(
repo_path=Path(repo_path),
package_name=repo_package_name, # type: ignore[unknown-argument]
layer_name=repo_layer_name,
)
}
Expand Down Expand Up @@ -141,7 +139,7 @@ def sanitize_kernel_mapping(self, model):
5. Each trust remote code key must be a bool.
6. Each revision or version key must exist mutually exclusive if it has been passed explicitly.
7. Each repo_name is a valid repository and layer name in the format 'org/repo:layer_name' (i.e., a string containing both a slash and a colon).
8. If a local path is detected, it should be in the format '/abs/path:layer_name'. The absolute path must include the `package_name`, like "/home/user/layer_norm".
8. If a local path is detected, it should be in the format '/abs/path:layer_name', where the absolute path points to the kernel repository, like "/home/user/layer_norm".

Args:
model: The model instance whose modules are checked for registered kernel_layer_name attributes.
Expand Down Expand Up @@ -286,7 +284,6 @@ def create_compatible_mapping(self, model, compile=False):
"cuda": {
Mode.INFERENCE: LocalLayerRepository(
repo_path=Path("/home/user/liger_kernels"),
package_name="liger_kernels",
layer_name="LigerRMSNorm",
)
}
Expand Down
Loading