I've been trying to work on this, and I have noticed a lot of the scripts assume pwd or cwd matches the code.
Changing the verify_correctness.py to this, uses a little pathlib trick to get absolute paths to files on the system.
#!/usr/bin/env python3
"""
Verify correctness of the optimized Metal kernel
Compares against PyTorch reference implementation
"""
import sys
import numpy as np
from pathlib import Path
my_folder = Path(__file__).resolve().parent
# Initialize Metal with OPTIMIZED kernel
try:
import _flash_attn_metal
_flash_attn_metal.initialize()
# Load common and OPTIMIZED kernel
common_src = open(my_folder / 'kernels/common.metal').read()
opt_src = open(my_folder / 'kernels/flash_attention_fwd_optimized.metal').read()
This means I can then run the verify_correctness.py outside of it's own folder, much like a regular package might run.
I've been trying to work on this, and I have noticed a lot of the scripts assume pwd or cwd matches the code.
Changing the verify_correctness.py to this, uses a little pathlib trick to get absolute paths to files on the system.
This means I can then run the verify_correctness.py outside of it's own folder, much like a regular package might run.