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

[Docs] Tensor value has no attribute 'argmax' #278

Open
Str-Gen opened this issue Jan 7, 2025 · 2 comments
Open

[Docs] Tensor value has no attribute 'argmax' #278

Str-Gen opened this issue Jan 7, 2025 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Str-Gen
Copy link

Str-Gen commented Jan 7, 2025

Where is the problem?

https://docs.modular.com/max/tutorials/get-started-with-max-graph

What can we do better?

In the max-graph-api example in the mnist.mojo file the compiler warns about a missing operation for a Tensor.
specifically probs.argmax(axis=1) 'Tensor[float32]' value has no attribute 'argmax'. Later use of the predicted variable is then recognized as not possible.
There is an arg_max operation for Graphs, but I would like to follow the example and not add the argmax to the Graph itself.
The mojo changelog mentions for version 24.2 that

The Tensor type now has argmax() and argmin() functions to compute the position of the max or min value. Note: this should return a Tensor[Int] but currently the output tensor is the same type as the input tensor. This will be fixed in a future release.

Since these operations are no longer implemented for the Tensor type, what should an idiomatic mojo solution look like?

probs = output.get[DType.float32]("output0")        
predicted = probs.argmax(axis=1) # this won't compile with max & mojo 24.6

label_ = Tensor[DType.index](TensorShape(1), int(label))
correct += int(predicted == label_)

Anything else?

I'm using the currently latest release of max and mojo (24.6).

@Str-Gen Str-Gen added the documentation Improvements or additions to documentation label Jan 7, 2025
@ehsanmok
Copy link
Member

ehsanmok commented Jan 7, 2025

It was removed in 24.6 in favour of better implementation later. Also discussed here. The Mojo API is unstable so please use the Python API. We'll update the examples later.

@Str-Gen
Copy link
Author

Str-Gen commented Jan 7, 2025

Will do, thank you for clarifying this so quicly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants