Skip to content

Commit b2a8e64

Browse files
authored
Refactoring centml modules (#23)
* Rename centml to ccompute * Change remote compilation server name to "compile-server" * Move config_instance and CompilationStatus to config.py * Move centml compiler backend registration to centml.compiler * Add string annotations to CompilationStatus enums
1 parent 86f3fd3 commit b2a8e64

File tree

11 files changed

+28
-30
lines changed

11 files changed

+28
-30
lines changed
File renamed without changes.

centml/__init__.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +0,0 @@
1-
import hidet
2-
import torch._dynamo
3-
from .compiler import backend
4-
5-
hidet.option.imperative(False)
6-
7-
# Register centml compiler backend to torch dynamo
8-
if "centml" not in torch._dynamo.list_backends():
9-
torch._dynamo.register_backend(compiler_fn=backend.centml_dynamo_backend, name="centml")

centml/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
def main():
77
parser = argparse.ArgumentParser(description="CentML command line tool")
8-
parser.add_argument("mode", choices=["server"], type=str)
8+
parser.add_argument("mode", choices=["compile-server"], type=str)
99

1010
args = parser.parse_args()
1111

12-
if args.mode == "server":
12+
if args.mode == "compile-server":
1313
server.run()
1414
else:
1515
raise Exception("Invalid mode")

centml/compiler/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
from .config import Config
1+
import torch._dynamo
22

3-
config_instance = Config()
3+
from .backend import centml_dynamo_backend
4+
5+
6+
# Register centml compiler backend to torch dynamo
7+
if "centml" not in torch._dynamo.list_backends():
8+
torch._dynamo.register_backend(compiler_fn=centml_dynamo_backend, name="centml")

centml/compiler/backend.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from hidet.graph.frontend.torch.interpreter import Interpreter
1616
from hidet.graph.frontend.torch.dynamo_backends import get_flow_graph, get_wrapper
1717
from hidet.runtime.compiled_graph import load_compiled_graph, CompiledGraph
18-
from centml.compiler import config_instance
19-
from centml.compiler.server_compilation import CompilationStatus
18+
from centml.compiler.config import config_instance, CompilationStatus
2019

2120

21+
hidet.option.imperative(False)
2222
base_path = os.path.join(config_instance.CACHE_PATH, "compiler")
2323
os.makedirs(base_path, exist_ok=True)
2424
server_url = f"http://{config_instance.SERVER_IP}:{config_instance.SERVER_PORT}"

centml/compiler/config.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
import os
2+
from enum import Enum
3+
4+
5+
class CompilationStatus(Enum):
6+
NOT_FOUND = "not_found"
7+
COMPILING = "compiling"
8+
DONE = "done"
29

310

411
class Config:
@@ -9,3 +16,6 @@ class Config:
916
CACHE_PATH = os.getenv("CENTML_CACHE_DIR", default=os.path.expanduser("~/.cache/centml"))
1017
SERVER_IP = os.getenv("CENTML_SERVER_IP", default="0.0.0.0")
1118
SERVER_PORT = os.getenv("CENTML_SERVER_PORT", default="8080")
19+
20+
21+
config_instance = Config()

centml/compiler/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from fastapi import FastAPI, UploadFile, HTTPException, BackgroundTasks, Response
77
from fastapi.responses import FileResponse
88
from fastapi.middleware.gzip import GZipMiddleware
9-
from centml.compiler.server_compilation import hidet_backend_server, storage_path, CompilationStatus, dir_cleanup
10-
from centml.compiler import config_instance
9+
from centml.compiler.server_compilation import hidet_backend_server, storage_path, dir_cleanup
10+
from centml.compiler.config import config_instance, CompilationStatus
1111

1212
logger = logging.getLogger(__name__)
1313

centml/compiler/server_compilation.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
11
import os
22
import shutil
33
import logging
4-
from enum import Enum
54
from typing import List
65
from torch import Tensor
76
from torch.fx import GraphModule
87
from hidet.runtime.compiled_graph import save_compiled_graph
98
from hidet.graph.frontend import from_torch
109
from hidet.graph.frontend.torch.interpreter import Interpreter
1110
from hidet.graph.frontend.torch.dynamo_backends import get_flow_graph, get_compiled_graph, preprocess_inputs
12-
from centml.compiler import config_instance
13-
14-
15-
class CompilationStatus(Enum):
16-
NOT_FOUND = 1
17-
COMPILING = 2
18-
DONE = 3
11+
from centml.compiler.config import config_instance
1912

2013

2114
storage_path = os.path.join(config_instance.CACHE_PATH, "server")

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
name='centml',
1515
version='0.1.0',
1616
packages=find_packages(),
17-
scripts=['bin/centml'],
18-
install_requires=REQUIRES
17+
scripts=['bin/ccompute'],
18+
install_requires=REQUIRES
1919
)
2020

tests/test_backend.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import hidet
88
from hidet.graph.frontend.torch.dynamo_backends import get_flow_graph
99
from centml.compiler.backend import Runner
10-
from centml.compiler.server_compilation import CompilationStatus
11-
from centml.compiler import config_instance
10+
from centml.compiler.config import config_instance, CompilationStatus
1211

1312

1413
class TestGetModelId(TestCase):

0 commit comments

Comments
 (0)