Skip to content

verify to be path independent #2

Description

@Lewiscowles1986

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions