[torch.compile] allow candidate compile sizes (#10984)
Signed-off-by: youkaichao <youkaichao@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import ast
|
||||
import copy
|
||||
import enum
|
||||
import hashlib
|
||||
@@ -2191,14 +2192,10 @@ class CompilationConfig(BaseModel):
|
||||
- use_inductor: whether to use inductor compilation.
|
||||
- False: inductor compilation is not used. graph runs in eager.
|
||||
- True: inductor compilation is used. one graph for symbolic shape
|
||||
is compiled. In addition, compile for different sizes specified
|
||||
in inductor_compile_sizes, using configurations
|
||||
is compiled. In addition, compile for cudagraph sizes that are
|
||||
in candidate_compile_sizes, using configurations
|
||||
in inductor_compile_config.
|
||||
- inductor_compile_sizes: sizes to compile for inductor.
|
||||
- inductor_specialize_for_cudagraph_no_more_than: an optional integer
|
||||
to specialize inductor for cudagraph sizes no more than the
|
||||
specified size. It is useful when we want to specialize inductor
|
||||
with a subset of cudagraph sizes.
|
||||
- candidate_compile_sizes: sizes to compile for inductor.
|
||||
- inductor_compile_config: additional configurations for inductor.
|
||||
- None: use default configurations.
|
||||
- inductor_passes: additional passes for inductor. It is a dictionary
|
||||
@@ -2227,8 +2224,7 @@ class CompilationConfig(BaseModel):
|
||||
])
|
||||
|
||||
use_inductor: bool = True
|
||||
inductor_specialize_for_cudagraph_no_more_than: Optional[int] = None
|
||||
inductor_compile_sizes: Optional[List[int]] = Field(default=None)
|
||||
candidate_compile_sizes: Optional[List[int]] = Field(default=None)
|
||||
inductor_compile_config: Dict = Field(default_factory=dict)
|
||||
inductor_passes: Dict[str, str] = Field(default_factory=dict)
|
||||
|
||||
@@ -2294,7 +2290,9 @@ class CompilationConfig(BaseModel):
|
||||
"""Parse the CLI value for the compilation config."""
|
||||
if cli_value in ["0", "1", "2", "3"]:
|
||||
return cls(level=int(cli_value))
|
||||
return CompilationConfig.model_validate_json(cli_value)
|
||||
# do not use `eval`, it is dangerous and can execute arbitrary code
|
||||
dict_value = ast.literal_eval(cli_value)
|
||||
return CompilationConfig.model_validate(dict_value)
|
||||
|
||||
def model_post_init(self, __context: Any) -> None:
|
||||
|
||||
@@ -2355,18 +2353,20 @@ class CompilationConfig(BaseModel):
|
||||
logger.info(("cudagraph sizes specified by model runner"
|
||||
" %s is overridden by config %s"),
|
||||
sizes_to_specialize, self.cudagraph_capture_sizes)
|
||||
if self.inductor_specialize_for_cudagraph_no_more_than is not None:
|
||||
assert self.inductor_compile_sizes is None, (
|
||||
"inductor_compile_sizes should be None when "
|
||||
"inductor_specialize_for_cudagraph_no_more_than is not None")
|
||||
self.compile_sizes = [
|
||||
x for x in self.capture_sizes
|
||||
if x <= self.inductor_specialize_for_cudagraph_no_more_than
|
||||
]
|
||||
else:
|
||||
if self.inductor_compile_sizes is None:
|
||||
self.inductor_compile_sizes = []
|
||||
self.compile_sizes = self.inductor_compile_sizes
|
||||
|
||||
if self.candidate_compile_sizes is None:
|
||||
self.candidate_compile_sizes = []
|
||||
self.compile_sizes = [
|
||||
x for x in self.candidate_compile_sizes if x in self.capture_sizes
|
||||
]
|
||||
ignored_sizes = [
|
||||
x for x in self.candidate_compile_sizes
|
||||
if x not in self.capture_sizes
|
||||
]
|
||||
if ignored_sizes:
|
||||
logger.warning(("candidate_compile_sizes %s are ignored "
|
||||
"because they are not cudagraph capture sizes."),
|
||||
ignored_sizes)
|
||||
|
||||
# sort to make sure cudagraph capture sizes are in descending order
|
||||
self.capture_sizes.sort(reverse=True)
|
||||
|
||||
Reference in New Issue
Block a user