modal.build

def build(
    _warn_parentheses_missing=None,
) -> Callable[[Union[Callable[[Any], Any], _PartialFunction]], _PartialFunction]:

Decorator for methods that should execute at build time to create a new layer in a modal.Image.

See the lifeycle function guide for more information.

Usage

@stub.cls(gpu="A10G")
class AlpacaLoRAModel:
    @build()
    def download_models(self):
        model = LlamaForCausalLM.from_pretrained(
            base_model,
        )
        PeftModel.from_pretrained(model, lora_weights)
        LlamaTokenizer.from_pretrained(base_model)