MCPcopy Create free account
hub / github.com/bruno686/VisPlay / CompileConfig

Class CompileConfig

configuration_utils.py:1591–1637  ·  view source on GitHub ↗

Class that holds arguments relative to `torch.compile` behavior, when using automatic compilation in `generate`. See [`torch.compile`](https://pytorch.org/docs/stable/generated/torch.compile.html) for more details on the arguments. Args: fullgraph (`bool`, *optional*, defaults

Source from the content-addressed store, hash-verified

1589
1590@dataclass
1591class CompileConfig:
1592 """
1593 Class that holds arguments relative to `torch.compile` behavior, when using automatic compilation in `generate`.
1594 See [`torch.compile`](https://pytorch.org/docs/stable/generated/torch.compile.html) for more details on the arguments.
1595
1596 Args:
1597 fullgraph (`bool`, *optional*, defaults to `True`):
1598 If `True`, requires that the whole forward be capturable in a single graph.
1599 dynamic (`bool` or `None`, *optional*):
1600 Whether to try to use dynamic shape graphs.
1601 backend (`str` or `Callable`, *optional*, defaults to `"inductor"`):
1602 Backend to be used.
1603 mode (`str`, *optional*, defaults to `"reduce-overhead"`):
1604 Controls balance between performance and overhead.
1605 options (`dict`, *optional*):
1606 A dictionary of options to pass to the backend.
1607
1608 Examples:
1609 ```python
1610 >>> from transformers import AutoModelForCausalLM, AutoTokenizer, CompileConfig
1611
1612 >>> tokenizer = AutoTokenizer.from_pretrained('google/gemma-2-2b')
1613 >>> model = AutoModelForCausalLM.from_pretrained('google/gemma-2-2b').cuda()
1614
1615 >>> # Automatic compile configuration, used with static cache
1616 >>> compile_config = CompileConfig(dynamic=True)
1617
1618 >>> # Generation with static cache and compile config
1619 >>> input = tokenizer.encode("Hello there, how", return_tensors="pt").cuda()
1620 >>> output = model.generate(
1621 ... input, do_sample=False, max_new_tokens=300, cache_implementation="static", compile_config=compile_config
1622 ... )
1623 >>> output_text = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
1624 ```
1625 """
1626
1627 fullgraph: bool = True
1628 dynamic: Optional[bool] = None
1629 backend: Union[str, Callable] = "inductor"
1630 mode: str = "reduce-overhead"
1631 options: Optional[dict] = None
1632 # Used to flag our `generate` call to compile on e.g. CPU. Often not optimal, but useful for testing purposes.
1633 _compile_all_devices = None
1634
1635 def to_dict(self) -> Dict[str, Any]:
1636 """Serializes this instance to a Python dictionary."""
1637 return copy.deepcopy({key: value for key, value in self.__dict__.items() if key != "_compile_all_devices"})

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected