lgatr.utils.compile
Helpers for using L-GATr networks with torch.compile().
Functions
|
Wrap |
|
Warm L-GATr's primitive caches for the model's current device and dtype. |
- lgatr.utils.compile.compile_model(model, *, compile_kwargs=None, activation_memory_budget=None)[source]
Wrap
model.forwardwithtorch.compile()in place.Rebinding
self.forwardrather than patching the class keeps the compilation local to this instance.- Parameters:
model (
Module) – Thetorch.nn.Modulewhoseforwardshould be compiled.compile_kwargs (
Mapping|None) – Forwarded verbatim totorch.compile()(e.g.mode,dynamic,fullgraph,backend). Any key omitted falls back to torch’s own default.activation_memory_budget (
float|None) – Fraction in[0, 1]for the partitioner’s activation-memory budget; lower values trade backward FLOPs for a smaller activation memory peak.None(default) leaves torch’s global setting untouched. Applied via a scoped patch only in effect while this model (re)compiles. Requirestorch>=2.4.
- Return type:
None
- lgatr.utils.compile.warmup_after_apply(model)[source]
Warm L-GATr’s primitive caches for the model’s current device and dtype.
Intended to be called from a
torch.nn.Module._apply()override so the caches are populated whenever the model is moved or cast (.to()/.cuda()/.float()/ etc.).- Parameters:
model (
Module) – Thetorch.nn.Modulewhose primitive caches should be warmed.- Return type:
None