# Copyright (c) 2025 SandAI. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import torch def replace_fa_with_sage(gm: torch.fx.GraphModule) -> torch.fx.GraphModule: for node in gm.graph.nodes: if node.op == "call_function" and node.target == torch.ops.athena.flash_attn_func: node.target = torch.ops.athena.sage_attn_func class FullGraphPassManager: """ A manager to apply various graph passes on the full graph before splitting. """ def __init__(self, pass_config): self.pass_config = pass_config def __call__(self, gm: torch.fx.GraphModule): if self.pass_config.enable_sage_attn: replace_fa_with_sage(gm)