|
| 1 | +import argparse |
| 2 | +import subprocess |
| 3 | + |
| 4 | +PROMPTS = ( |
| 5 | + "The emergence of deep learning domain-specific languages (DSLs) has substantially reduced the obstacles in developing high-performance, cross-platform compute kernels, but current DSLs", |
| 6 | + "Driven by recent advancements in the AI industry, the AI accelerator sector has increasingly diversified, with vendors developing their own hardware architectures and programming models, such as NVIDIA", |
| 7 | +) |
| 8 | + |
| 9 | +NUM_WARMUP_ITERATIONS = 1 |
| 10 | + |
| 11 | +NUM_PROFILING_ITERATIONS = 3 |
| 12 | + |
| 13 | +BACKENDS = ("ninetoothed", "triton", "torch") |
| 14 | + |
| 15 | +ALL_MAX_NEW_TOKENS = (128, 512, 2048) |
| 16 | + |
| 17 | + |
| 18 | +if __name__ == "__main__": |
| 19 | + parser = argparse.ArgumentParser(description="Run experiments.") |
| 20 | + |
| 21 | + parser.add_argument( |
| 22 | + "--model", |
| 23 | + type=str, |
| 24 | + required=True, |
| 25 | + help="Path to the model or model identifier from Hugging Face.", |
| 26 | + ) |
| 27 | + |
| 28 | + args = parser.parse_args() |
| 29 | + |
| 30 | + model_name_or_path = args.model |
| 31 | + |
| 32 | + radon_commands = ( |
| 33 | + ( |
| 34 | + "radon", |
| 35 | + "cc", |
| 36 | + "--show-complexity", |
| 37 | + "--json", |
| 38 | + "--output-file", |
| 39 | + "cc.json", |
| 40 | + "ops/", |
| 41 | + ), |
| 42 | + ("radon", "mi", "--show", "--json", "--output-file", "mi.json", "ops/"), |
| 43 | + ("radon", "raw", "--json", "--output-file", "raw.json", "ops/"), |
| 44 | + ("radon", "hal", "--json", "--output-file", "hal.json", "ops/"), |
| 45 | + ) |
| 46 | + |
| 47 | + for command in radon_commands: |
| 48 | + subprocess.run(command, check=True) |
| 49 | + |
| 50 | + with open("code_metrics.tex", "w") as f: |
| 51 | + subprocess.run(("python", "compare_code_metrics.py"), stdout=f, check=True) |
| 52 | + |
| 53 | + for max_new_tokens in ALL_MAX_NEW_TOKENS: |
| 54 | + for backend in BACKENDS: |
| 55 | + with open(f"infer_{max_new_tokens}_{backend}.json", "w") as f: |
| 56 | + subprocess.run( |
| 57 | + ( |
| 58 | + "python", |
| 59 | + "infer.py", |
| 60 | + "--model", |
| 61 | + model_name_or_path, |
| 62 | + "--prompts", |
| 63 | + *PROMPTS, |
| 64 | + "--max-new-tokens", |
| 65 | + str(max_new_tokens), |
| 66 | + "--device", |
| 67 | + "cuda", |
| 68 | + "--backend", |
| 69 | + "ninetoothed", |
| 70 | + "--num-warmup-iterations", |
| 71 | + str(NUM_WARMUP_ITERATIONS), |
| 72 | + "--num-profiling-iterations", |
| 73 | + str(NUM_PROFILING_ITERATIONS), |
| 74 | + ), |
| 75 | + stdout=f, |
| 76 | + check=True, |
| 77 | + ) |
| 78 | + |
| 79 | + with open("performance_metrics.tex", "w") as f: |
| 80 | + subprocess.run( |
| 81 | + ("python", "compare_performance_metrics.py"), stdout=f, check=True |
| 82 | + ) |
0 commit comments