Skip to content

Implementation of the gradient approximation for the SAM objective (eq3) #14

@zhipeng-wei

Description

@zhipeng-wei

I have read your paper and code carefully.
You use the p as 2, thus SAM firstly maximizes the objective loss function by adding rho * normalized gradients to models' parameters (

(_, (inner_state, _)), grad = jax.value_and_grad(
)
And SAM calculates gradients in this noised model again (
(_, (_, logits)), grad = jax.value_and_grad(
).
In your paper, the gradient is calculated with respect to the original model's parameters, unlike the code which calculates gradient with respect to the noised model's parameters.

Are these two the same?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions