Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SLM] Implement pattern replacement #16686

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Lunderberg
Copy link
Contributor

Prior to this commit, if an optimized nn.Module implementation were defined, either the model definition needed to be rewritten to include the optimized implementation, or the user needed to write their own nn.Mutator implementation.

This commit implements nn.replace_implementation, which provides a nn.Mutator that replaces all instances of a nn.Module with an optimized implementation. This allows a user to write optimized implementations as subclasses, such as shown below.

class BaseImplementation(nn.Module):
    ...

class OptimizedImplementation(BaseImplementation):
    ...

After defining the optimized implementation, nn.replace_implementation(OptimizedImplementation) returns a nn.Mutator that can inject the optimized module into an existing end-to-end SLM model. In addition, the SLM-to-SLM transformation can be converted into a Relax-to-Relax transformation, allowing an easy path for migrating optimized kernels into a Relax optimation pipeline.

@Lunderberg
Copy link
Contributor Author

Lunderberg commented Mar 6, 2024

This PR is currently marked as a draft, both because the unit tests depend on functionality introduced in #16697, and to allow discussion on the feature.

@Lunderberg Lunderberg force-pushed the slm_inject_optimized_kernel branch 2 times, most recently from c6fdea8 to 6493a71 Compare March 11, 2024 15:35
@Lunderberg Lunderberg force-pushed the slm_inject_optimized_kernel branch from 559cae7 to 2401b40 Compare March 18, 2024 20:57
@Lunderberg Lunderberg force-pushed the slm_inject_optimized_kernel branch 2 times, most recently from 32e071d to f94dab6 Compare June 28, 2024 19:37
@Lunderberg Lunderberg marked this pull request as ready for review June 28, 2024 19:38
@Lunderberg Lunderberg changed the title [Draft][SLM] Implement pattern replacement [SLM] Implement pattern replacement Jun 28, 2024
@Lunderberg
Copy link
Contributor Author

Finally getting back around to this one, ready for review.

Prior to this commit, if an optimized `nn.Module` implementation were
defined, either the model definition needed to be rewritten to include the
optimized implementation, or the user needed to write their own
`nn.Mutator` implementation.

This commit implements `nn.replace_implementation`, which provides a
`nn.Mutator` that replaces all instances of a `nn.Module` with an
optimized implementation.  This allows a user to write optimized
implementations as subclasses, such as shown below.

```python
class BaseImplementation(nn.Module):
    ...

class OptimizedImplementation(BaseImplementation):
    ...
```

After defining the optimized implementation,
`nn.replace_implementation(OptimizedImplementation)` returns a
`nn.Mutator` that can inject the optimized module into an existing
end-to-end SLM model.  In addition, the SLM-to-SLM transformation can
be converted into a Relax-to-Relax transformation, allowing an easy
path for migrating optimized kernels into a Relax optimation pipeline.
@Lunderberg Lunderberg force-pushed the slm_inject_optimized_kernel branch from f94dab6 to 0198ba7 Compare September 11, 2024 16:13
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