Modular

M

Modular

This server is the home of the MAX and Mojo community. Join us to chat about all things Modular!

Join

questions

community-showcase

Seeking Clarification on Current and Future Tensor Library Support in Mojo

I wonder if someone can clarify the current state and future direction of a Tensor library for Mojo. I understand that Tensor won't stay in the standard library and i think to understand the rationale behind it. We have also NuMojo, which looks very promising. It is currently based on Tensor but aims to have "Native array types" as a long-term goal. Not clear about the situation, I implemented my own vectorized yet simple Vector and Matrix structs for my KAN experiments. They work, my KAN implementaton outperforms the Python implementation i ported to Mojo (which is numpy based). However, I just found out these are extremely slow compared to torch.matmul, etc. ...

Parameterized function definitions in traits

Is this possible? ``` trait X: fn x[Y: AnyType](self, y: Y) -> Y: pass...

How to declare a function type in a trait?

This is a simple class in Python ```python class MyPair: def init(first, second):...

About lifetimes

Hi, I'm playing with FFI and I need to know how to manage correctly some lifetimes. Let's take an example : ``` alias external_func = fn(UnsafePointer[JpegErrorMgr]) -> UInt...

Benchmarking code that raises

I am trying to use benchmark to time numpy code. However, numpy raises and it appears that benchmark.run cannot handle a function that raises. I am not a python programmer, so I am not familiar with the exception syntax. Is there a way to wrap numpy code such that the surrounding function does not raise?

FFI

Hi, I'm working on FFI and I've got two small questions : 1 - what is the equivalent of size_t in Mojo ? 2 - Dynamic linking is easy but I haven't found a way to proceed with a static library (.a file). Is there a clean and official way to do that ?...

example of python code calling a mojo lib and its mojo code

I would like to give a try mojo a nd create a library in can use in python code. I would like to check if anyone has examples of doing this. Guess the python part is easy as it is going to be as any other library but i am interested on how to process ffi in mojo(cstrings etc)

Google TPUs with Mojo language?

Sup, I'm creating a resource-intensive AI (at least 3-4x more resource-intensive than LLMs), so I'm considering a stack which would allow me fast computation cheap (while making dev relatively easy). Would using JAX and TPUs not work with Mojo? As far as I see, using TPUs is the absolute fastest we can get for deep learning. (or is it? Would MAX inference engine be faster?) ...

Importing package in test

Hey - not sure if I'm doing something wrong with my env setup but my tests in my test/ folder can't seem to import from package_name/. My folder structure is ``` repo/ package_name/...

How to understand Mojo's compiler optimization capabilities?

This is something that’s been bugging me for a while. I am afraid there’s no clear answer, but I’m curious how you guys handle it. How can I figure out what optimizations the compiler is doing anyway instead of implementing them myself (vectorize etc) ? Implementing them myself is often easy with Mojo, but still it’s prone to errors, makes the code harder to read, and things like choosing simd_width in the code might be less optimal than letting the compiler decide based on the machine the code is running on. ...

Can I use Mojo🔥 for web development and app development?

#general Can I use Mojo🔥 for web development and app development?

max modules import error while running bert python torch script

>>bash run.sh
+ INPUT_EXAMPLE='Paris is the [MASK] of France.' + MODEL_PATH=../../models/bert-mlm.torchscript ++ dirname run.sh...

error running bash run.sh after installing max

error running bash run.sh after installing max it says >>bash run.sh ...

UnsafePointer[T].initialize_pointee_copy error

Hi, I try to store multiple values in memory initialize by an UnsafePointer[T], like the official documentation states but I've got the error "invalid call to 'initialize_pointee_copy': argument #0 cannot be converted from 'UnsafePointer[T, 0]' to 'UnsafePointer[T, 0]'" ...

list of pre-implemented models?

I see there are examples that run Llama2, Llama3, TinyLlama, and Stable Diffusion. Is there a list of pre-implemented models that can be used? Or is it just these examples? https://github.com/modularml/max/tree/main/examples/graph-api/pipelines/quantize_tinystories

dynamic traits are not supported yet

Hello. Nooby question. I am working on some middleware for the lightbug project and want to build a chain-of-responsibility design pattern to handle the different aspects of processing a request / response: ``` Middleware is an interface for processing HTTP requests. Each middleware in the chain can modify the request and response. trait Middleware:...

Mandelbrot example equivalent python code

I was reading and following the code in the blog post https://www.modular.com/blog/how-mojo-gets-a-35-000x-speedup-over-python-part-1. I was trying to run the snippets provided but they don't compile by themselves because they are not complete. I found the source code in github https://github.com/modularml/mojo/blob/main/examples/mandelbrot.mojo. I ran this and it works with these results on my machine: Number of physical cores: 8 Vectorized: 14.634963190184047 ms Parallelized: 4.1496295025728989 ms Parallel speedup: 3.5268120156534257...

Best way to make a struct of CollectionElements to conform to CollectionElement.

I am still confused about best practices for __moveinit__ and __copyinit__. Let's say i have a struct with two variables, which are both structs which conform to the CollectionElement trait, how to define __moveinit__ and __copyinit__ for this struct. Will this do?...

Question about iterating a list of strings

Hi, I've got a background in Rust (10 years) and in Python (1 year) and I try to learn Mojo. I've try this : ```...