def requires_grad(model, flag=True):
    """
    Set requires_grad flag for all parameters in a model.
    """
    for p in model.parameters():
        p.requires_grad = flag
Set requires_grad flag for all parameters in a model.
opensora/utils/utils.py