in scripts/init-kernel.py [0:0]
def main():
# Get the directory where this script is located
script_dir = pathlib.Path(__file__).parent.resolve().parent.resolve()
# Create argument parser
parser = argparse.ArgumentParser(
description="Create ReLU example files in the specified directory"
)
parser.add_argument(
"target_dir", help="Target directory where files will be created"
)
args = parser.parse_args()
# Get the target directory from arguments
target_dir = args.target_dir
# Create the target directory if it doesn't exist
if not os.path.exists(target_dir):
os.makedirs(target_dir)
print(
f"\n{Colors.CYAN}{Colors.BOLD}Created directory: {Colors.BOLD}{target_dir}{Colors.ENDC}\n"
)
else:
print(
f"\n{Colors.CYAN}{Colors.BOLD}Directory already exists: {Colors.BOLD}{target_dir}{Colors.ENDC}\n"
)
# get files from examples/relu
relu_dir = script_dir / "examples" / "relu"
for root, _, files in os.walk(relu_dir):
for file in files:
file_path = os.path.join(root, file)
with open(file_path, "r") as f:
content = f.read()
# Replace kernel-builder.url with path:../ in flake.nix
if file_path.endswith("flake.nix"):
kernel_builder_url_start = content.find("kernel-builder.url =")
kernel_builder_url_end = content.find(";", kernel_builder_url_start)
content = (
content[:kernel_builder_url_start]
+ 'kernel-builder.url = "path:../"'
+ content[kernel_builder_url_end:]
)
target_file = file_path.replace(str(relu_dir), target_dir)
create_file_with_content(target_file, content)
print(f" {Colors.BOLD}{target_dir}/{Colors.ENDC}")
print_tree(target_dir)
print(
f"\n{Colors.GREEN}{Colors.BOLD}✓ Success!{Colors.ENDC} All files for the ReLU example have been created successfully."
)
print(f"\n{Colors.CYAN}{Colors.BOLD}Next steps:{Colors.ENDC}")
commands = [
"nix run nixpkgs#cachix -- use huggingface",
f"cd {target_dir}",
"git add .",
"nix develop -L",
]
for index, command in enumerate(commands, start=1):
print(
f" {Colors.YELLOW}{index}.{Colors.ENDC} {Colors.BOLD}{command}{Colors.ENDC}"
)
print(
f"\none line build:\n{Colors.GREY}{Colors.BOLD}{' && '.join(commands)}{Colors.ENDC}{Colors.ENDC}"
)
print(f"\n{Colors.CYAN}{Colors.BOLD}Run the tests{Colors.ENDC}")
print(
f" {Colors.YELLOW}{1}.{Colors.ENDC} {Colors.BOLD}pytest -vv tests/{Colors.ENDC}"
)
print("")