stardance has been extended another month! the new deadline is october 31 :)

You are browsing as a guest. Sign up (or log in) to start making projects!

Muhammad_Ahmad

@Muhammad_Ahmad

Joined June 3rd, 2026

  • 16Devlogs
  • 2Projects
  • 2Ships
  • 15Votes
I do maths and AI stuff...
Open comments for this post

2h 29m 39s logged

After debugging for a week. It’s finally done. There’s a whole story behind this though.

1. Bundling a python project with pyinstaller

To ship my project I had to create an exe file out of my project, and for that I used pyinstaller. Ran into multiple micro-dependencies issues like groovy and safehttpx. And the exe file was over 6 GBs

2. Pytorch CPU hell

To reduce the exe file size, I had to use the cpu only torch packages. But when pyinstaller bundled those, I ran into some dependency issue by c10.dll file. And no matter how many workarounds and things I tried I just couldn’t fix it. I just knew at that moment that this is just not the way. There were also some issues regarding Intel OpenMP thread collision, I don’t even know what that means! :(

3. ONNX the savior

Researching a bit I stumbled upon onnx runtime engine for pytorch models. So, I created another app script this time with onnx model loading and numpy based preprocessing (sadly I couldn’t even use the preprocessing pipeline from pytorch). But this was simply the beginning….

4. ONNX dependency hell and incompatibility with other packages

When I tried building the onnx based app, the first issue was a silent failure, no log, no warning just exe file not running at all… It was some silent C level crash that python couldn’t detect, so I changed my app script again and added fault_handler. There was a raw memory collision between gradio and onnx for dll space. I changed the import order for onnx first but pyinstaller still hooked up onnx runtime dll’s to some third party package’s dll files.

Finally after that, I manually wrote a hook script and grabbed the dll files manually myself to inject into pyinstaller analysis object.

0
0
6
Ship Pending review

Made a image classifier model based on the resnet-18 architecture. I trained it on cifar-10 (which is a dataset for 10 classes of images airplanes, cars, trucks, ships, cats, dogs, horses, birds, frogs, deer). The hardest part was to understand the why behind the model’s inductive bias and translating the maths into code I guess. You can check the code out on github and try out the deployed wrapper around the model on hugging face spaces :>

  • 6 devlogs
  • 6h
Try project → See source code →
Open comments for this post

31m 26s logged

Devlog 1.2

I mainly focused on profiling the model’s performance, and I found the model’s inference to be taking ~200 ms on GTX 1650. But I compiled the model with torch.compile() which basically fuses all the cuda operations in one big monolithic kernel and my jaw dropped seeing 20x performance boost taking only ~8 ms.

Oh and I also profiled the compiled model wrong the first time and also recorded the lazy jit compilation of the model during the first pass. The solution of it was to synchronise cuda with CPU and then run the profiler.

(This took wayyy more than just 31 mins, I had to install and set up WSL to run torch.compile because pytorch’s backend uses triton which doesn’t support windows).

0
0
11
Open comments for this post

1h 38m 15s logged

DevLog 1.1

  • Fixed Bugs
  • Wrote a training ipynb file so I can train the model on google colab or kaggle
  • Tried different hyperparameters for better generalization and training efficiency
  • Edited .gitignore
0
0
17
Open comments for this post

2h 9m 3s logged

First off, I needed to understand how ResNet worked so I read the paper: https://arxiv.org/abs/1512.03385

After reading made a plan and visual to follow and implement in the code, starting off simple I choose to implement ResNet-18.

In code:

  • Downloaded Cifar-10 (this took a long time somewhy)
  • Defined the Residual Blocks
  • Encapsulated the Resnet Model
  • Wrote training script and some utility functions
  • Tested inference and shape match
0
0
18
Ship

I made a N Gram Model in C++, which is a fundamental and early NLP model used for text generation and text suggestion in search engines. The hardest part was understanding the theoretical concepts and applying them in code. The project files are released on github and also published as a release for easy download. The readme states clear simple instruction to run the model (it’s very easy, trust, just one command). You can interact with it on the CLI (for now i guess).

  • 8 devlogs
  • 12h
  • 10.44x multiplier
  • 124 Stardust
Try project → See source code →
Open comments for this post

1h 40m 59s logged

Final touches

  • Added a bigger corpus i.e. wikitext2 by salesforce AI Research.
  • Credited corpus and linked associated license.
  • Wrote a python script to read the parquet format corpus and turn it into .txt format.
  • Some minor changes in code.
0
0
2
Open comments for this post

1h 18m 48s logged

Implemented Model Evaluation with Perplexity

Perplexity (a metric borrowed from information theory) acts a summarized evaluation metric for your model, that intuitively evaluates how much your model branches off in generating texts.

Mathematically, it’s a geometric mean of the inverse probabilities as calculated by the model, normalized by sequence length.

For seen texts, my model achieved a perplexity around 20-30, and for unseen texts it varied alot due to random picking of tokens in that case.

0
0
1
Open comments for this post

1h 3m 11s logged

Implemented Laplace Smoothing in the model

Smoothing refers to generalization of n gram model to texts they haven’t seen before. Laplace smoothing (also known as add-one smoothing) is the simplest type of smoothing that avoids the probability estimates to reach zero when handling unseen token or sequences.

It is quite easy to implement this in code, just add one in the numerator of probability formula and add vocabulary size in the denominator.

0
0
2
Open comments for this post

1h 1m 47s logged

  • Implemented probability estimates of each word using the formula:
    Counts of gram sequence in corpus/ Counts of context window sequence in corpus

  • Improved the I/O logic a bit aswell, the debug statements are there but commented.

0
0
1
Open comments for this post

1h 53m 58s logged

  • Made module for estimating probabilities of words given a context window using MLE (Maximum Likelihood Estimation).
  • Fixed the mapping of tokens back to strings, by using temporary dynamically allocated array and copying it into vector.
0
0
1
Open comments for this post

2h 5m 5s logged

Made NGram class that can count occurences of the specified n grams in the corpus. Also, the tokenizer now has another module to map unique tokens to ints for memory efficiency. Now, I shall move onto estimating probabilities of each token given a context window.

0
0
1
Open comments for this post

1h 16m 50s logged

Overview: N Gram Model is a fundamental model in Natural Language Processing used to predict next word in a given sequence. It relies on markov’s assumption that the probability estimate of a word relies on it’s immediate preceding words rather than the whole text/sentence.

What I have made uptill now: I have made the first module required for this project which is a Tokenizer, a tokenizer takes a text corpus and separately stores each word or token in a lookup table.

Future Direction: The core mechanism of N gram models, which is probability estimates for each n word sequence using frequency found in the corpus. Further, I would want to add smoothing to these probability estimates and add model evaluating metrics like perplexity.

0
0
1

Followers

Loading…