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

WebAssembly triggers ggml_assert_aligned on Mac M1 #653

Open
saraalrawi opened this issue Dec 14, 2023 · 2 comments
Open

WebAssembly triggers ggml_assert_aligned on Mac M1 #653

saraalrawi opened this issue Dec 14, 2023 · 2 comments

Comments

@saraalrawi
Copy link

saraalrawi commented Dec 14, 2023

I built a simple autoencoder model using ggml.

In the forward function and after running the matrix multiplication, and activation functions, I run:

ggml_build_forward_expand(gf, out_layer_1);

Forward function:

struct ggml_tensor *logits = forward(&model, ctx0 ,&gf ,real_data);

where ctx0 is the context initialised with the following parameters:

                   struct ggml_init_params params = {
		//.mem_size   = 1024ll*1024ll*1024ll, too big! cant grow memory error 
		.mem_size   = 16 * 16 * 1024 * 1024,
		.mem_buffer = NULL,
		.no_alloc   = false,
	        };
	
	
	// get context0 
 	struct ggml_context *ctx0 = ggml_init(params); 

and real_data is a tensor of size 200x400 filled with float numbers.

I can train the model and run inference as well by compiling and running the compiled C++ code.

Later, I compiled the code into WebAssembly with MAXIMUM_MEMORY=4GB

My issue now: I receive the following error, which is an assertion gets triggered when a new object is created (probably)

Once the program reaches:

ggml_build_forward_expand(gf, out_layer_1);

Can anyone help? is it because of the memory size? should I allocate memory differently?

My hardware is MacBook Pro Apple M1 64

@saraalrawi saraalrawi changed the title WebAssembly + GGML_MEM_ALIGN WebAssembly + GGML_MEM_ALIGN + Mac M1 Dec 14, 2023
@saraalrawi saraalrawi changed the title WebAssembly + GGML_MEM_ALIGN + Mac M1 WebAssembly triggers ggml_assert_aligned on Mac M1 Dec 14, 2023
@FSSRepo
Copy link
Collaborator

FSSRepo commented Dec 16, 2023

I could help you. First of all, the way you want to allocate memory to the context is wrong. ctx0 is for building the computation graph and only requires memory for tensor metadata. The tensor data should be stored in a backend buffer using ggml-alloc, you can see a simple example here: simple-ggml.

@saraalrawi
Copy link
Author

@FSSRepo Thank you very much for your reply!

The example you provided works as WebAssmbly (with little adaptation).
I will try to apply the concept for training a neural network now. :-)

Let's keep the issue open till I am done so I can provide an example to be used by others :-)

Happy coding with ggml

CCLDArjun pushed a commit to CCLDArjun/ggml that referenced this issue Dec 18, 2023
…#653)

* Initial version of q4_0 matrix multiplication benchmark

* Bugfix: Added dependency to ggml.o to benchmark

* Reviewer requests: added parameter for threads, switched to ggml_time_us()

* Reviewer input: removed rtsc, use epsilon for check

* Review comment: Removed set_locale

* Feature: Param for numer of iterations, Bugfix for use of parameter threads

* Reviewer suggestion: Moved to examples

* Reviewer feedback: Updated clean: and benchmark: sections

---------

Co-authored-by: Georgi Gerganov <[email protected]>
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

No branches or pull requests

2 participants