Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prune tensor expr inspect results #1272

Merged
merged 7 commits into from
Jul 27, 2023
Merged

Conversation

polvalente
Copy link
Contributor

Adds pruning of in-between expressions so that we
it's easier to analyze the overall behavior of a Nx.Defn.Expr

@polvalente polvalente self-assigned this Jul 27, 2023

true ->
parameters
end
Copy link
Contributor Author

@polvalente polvalente Jul 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently this prints:

Nx.default_backend(Nx.Defn.Expr)
param_tensor = &Nx.Defn.Expr.parameter(Nx.Defn.Expr.tensor(&1), &2)
Enum.reduce(1..50, param_tensor.(0, 0), &Nx.add(&2, param_tensor.(&1, &1))) |> IO.inspect(limit: 10); nil
#Nx.Tensor<
  s64
  
  Nx.Defn.Expr
  parameter a:0     s64
  parameter b:1     s64
  parameter d:2     s64
  parameter f:3     s64
  parameter h:4     s64
  parameter j:5     s64
  parameter l:6     s64
  parameter n:7     s64
  parameter p:8     s64
  ...               
  parameter dv:50   s64
  ...               
  de = add dc, dd   s64
  dg = add de, df   s64
  di = add dg, dh   s64
  dk = add di, dj   s64
  dm = add dk, dl   s64
  do = add dm, dn   s64
  dq = add do, dp   s64
  ds = add dq, dr   s64
  du = add ds, dt   s64
  dw = add du, dv   s64
>

Comment on lines 1600 to 1602
(len = length(parameters)) > opts.limit ->
[h | t] = parameters
[h, {"...", ""} | Enum.drop(t, len - opts.limit)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(len = length(parameters)) > opts.limit ->
[h | t] = parameters
[h, {"...", ""} | Enum.drop(t, len - opts.limit)]
length(parameters) > opts.limit ->
[h | t] = parameters
[h, {"...", ""} | Enum.take(t, -(opts.limit - 1))]

@josevalim
Copy link
Collaborator

@polvalente sorry, I pushed something but I messed up.

@josevalim
Copy link
Collaborator

@polvalente it shuold be good now. I used your idea of appending/prepending to the parameters and using the limit as a flag of when to do that once, so we don't need to do a later check. We just need tests and we are good. :)

@polvalente
Copy link
Contributor Author

@polvalente it shuold be good now. I used your idea of appending/prepending to the parameters and using the limit as a flag of when to do that once, so we don't need to do a later check. We just need tests and we are good. :)

Awesome! I'll work on testing this :)

Nx.Defn.Expr
... \s
>\
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josevalim tests are kinda verbose, but I wanted to cover most edge cases

@polvalente polvalente marked this pull request as ready for review July 27, 2023 19:32
@polvalente polvalente merged commit 101be51 into main Jul 27, 2023
9 checks passed
@polvalente polvalente deleted the pv-feat/limit-exprs branch July 27, 2023 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants