Skip to content

Commit

Permalink
improved html visualization and monitoring on the graidents, and rese…
Browse files Browse the repository at this point in the history
…t all gradients correctly in moving batch
  • Loading branch information
liyin2015 committed Dec 23, 2024
1 parent f9e5d39 commit 9c0c5b6
Show file tree
Hide file tree
Showing 17 changed files with 682 additions and 335 deletions.
2 changes: 1 addition & 1 deletion adalflow/adalflow/core/retriever.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def forward(
top_k = Parameter(
data=top_k or self.top_k,
name="top_k",
requires_opt=True,
requires_opt=False,
param_type=ParameterType.HYPERPARAM,
)
if input is None:
Expand Down
17 changes: 17 additions & 0 deletions adalflow/adalflow/optim/grad_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def backward(self, *, response: "Parameter", id: str = None, **kwargs):
Subclass should implement this method if you need additional backward logic.
"""
from adalflow.optim.parameter import GradientContext

log.info(f"GradComponent backward: {response.name}")
children_params = response.predecessors
Expand All @@ -174,11 +175,27 @@ def backward(self, *, response: "Parameter", id: str = None, **kwargs):

# pass the current gradient to pred

# TODO: each gradcomponent will have its own context, but
# passing the successor's gradient.data to the current.

for grad in response.gradients:
# make a copy of the gradient
grad = deepcopy(grad)
# update the gradient context and from and to
grad.update_from_to(response, pred)
grad.is_default_copy = True
grad.add_context(
GradientContext(
variable_desc=pred.role_desc,
response_desc=response.name,
# context=f"""""", # TODO: check the forward pass component trace
context=f"""{response.component_trace}""",
)
)

# grad.from_response_id = response.id
# grad.name = f"{grad.name}_to_{pred.name}"

pred.add_gradient(grad)
# pred.add_gradient(
# gradient=Parameter(
Expand Down
Loading

0 comments on commit 9c0c5b6

Please sign in to comment.