| 74 | |
| 75 | |
| 76 | def read_all_files(directory): |
| 77 | # Just open each file and read the whole thing into memory. This is a hack |
| 78 | # because Modal's `Volume` file system has really bad perf on first read, |
| 79 | # especially if you're grabbing just a piece at a time like SafeTensors |
| 80 | # does. |
| 81 | def read_file(file): |
| 82 | with open(file, "r") as f: |
| 83 | f.read() |
| 84 | |
| 85 | with ThreadPoolExecutor() as executor: |
| 86 | for root, _, files in os.walk(directory): |
| 87 | for file in files: |
| 88 | file_path = os.path.join(root, file) |
| 89 | executor.submit(read_file, file_path) |
| 90 | |
| 91 | |
| 92 | @stub.cls( |