RSSAmplifier

Blog

Code Musings

Recent content on Code Musings

arunma.comRSS feed ↗41 posts

Latest posts

Fine-Tuning a 4B Model Into Your Own Persona, Part 2: Training, Eval, Ship

Part 1 ended with train.jsonl , val.jsonl and a passes_all percentage. The passes_all percentage is our ceiling , the best score we can hope for from the model trained on that corpus. This post is the rest: LoRA SFT on Qwen3-4B, evaluating against the same five binary questions, iterating manually with hand-corrections and converting to GGUF for easier local inference. Code is in the same repo:…

Fine-Tuning a 4B Model Into Your Own Persona, Part 1: The Data

The previous post was the story: three rounds of fine-tuning, $35 of compute, what worked and what didn’t. This two-part series is the recipe. What we do, in order, to turn a stock 4B base model into a specific character. Part 1 (this post) is the data pipeline. Writing the persona prompt, generating a synthetic corpus with Gemini, cleaning it and evaluating it with Claude Haiku. By the end…

Costume vs. Character: How $35 of SFT Turned Qwen Into Monty

That’s Qwen3-4B-Instruct , a four-billion-parameter model that runs comfortably on my laptop, answering a question about its own identity. Out of the box it would have said “I am Qwen, a large-scale language model independently developed by the Tongyi Lab under Alibaba Group.” After fine-tuning it says it’s Monty , invents a sabbatical, and turns the question back on me.…

Small Dog, Small Language Model: Training a Transformer for $5

“Once upon a time, there was a dog named Cookie. She loved to play fetch with her owner. One day, they went for a walk in the park and found a big ball. Cookie picked it up with her mouth and brought it back to her owner…” That paragraph above? Generated by a 91-million-parameter transformer I trained from scratch over a Saturday afternoon. The dog Cookie is real. She’s mine. She is…

What is HyperLogLog and how to build yours in Rust

Typically, counting the number of unique values in a dataset is an easy problem. You maintain a BST or HashSet to remove duplicates as they come in while keeping track of the count of inserted unique values. It takes O(n) space, which is acceptable for smaller datasets. However, for large datasets, storage becomes quickly expensive, especially if you would like to keep track of counts in…

Build your own CountMinSketch in Rust

While discussing about Counting Bloom Filter , we came across this function called estimated_count which attempts to calculate the number of times an element was present in the bloom filter. During the discussion, I also said that the Counting Bloom Filter is not the best datastructure for calculating the count of an item. CountMinSketch is a good data structure to do that. And we’ll see…

Build your own Counting Bloom Filter in Rust

A Counting Bloom Filter is a probabilistic data structure that helps us quickly check if an element is present in a set or not. You might argue “Hey, can’t a simple Set do it?”. Yes, indeed and to top it, Counting Bloom Filter is not even 100% accurate and expects us to provide the expected “false positive rate”. Where Bloom Filters shine is that for large volumes of…

The beautiful simplicity of Apache Ranger plugin

If you are here, you already know what Apache Ranger is. It is the most popular, if not the only, way to manage security in the Hadoop framework. It has integrations with Active Directory, Kerberos and various others for authentication but I believe the most interesting feature is its authorization support. Being part of the Hadoop ecosystem, one would not be surprised that it has inbuilt support…

Creating a YARN Application using Scala

I have been recently playing with Apache Amaterasu , which is an amazing project that helps to deploy data pipelines. It’s still incubating and has a super-friendly team of engineers working on it. Some exciting features are lined up. Don’t take my word for it. Please check it out yourself . Amaterasu launches containers (on YARN/Mesos) all by itself for each of the stages in your data…

Scala notes - Futures - 3 (Combinators and Async)

In the previous parts of this post, we discussed about Futures and Promises . In this last part, we’ll compose Futures using its powerful combinators. Composing Futures : In the first post , we saw how to extract a value from Future using onComplete , foreach and in testcases using Await.result . Extracting a value from a single Future is good but many a time we spawn more than one…

Scala notes - Futures - 2 (Promises)

In the last post, we saw how to extract values from the Future upon onComplete and their counterparts - onSuccess and onFailure . We also saw how to use Await.result in Testcases to block and get the value from Future. In this post, we’ll discuss briefly about the relationship between a Promise and a Future . Promise The concepts Promise and a Future go hand in hand. A…

Scala Notes - Futures - 1

Almost all modern programming languages have a Future-Promise idiom for concurrent programming. I don’t intend to bore you with why we need higher level of concurrency abstractions. Instead, in this post, we’ll cut to the chase and discuss only about Scala’s approach to Futures. A scala.concurrent.Future is a representation of a value that is yet to be realized. This value is…

Akka Notes - Finite State Machines - 2

In the first part of notes on Akka FSM, we saw the basics of Akka FSM and the outline of the Coffee vending machine that we planned to build - the structure of the Actor and a list of messages we pass to the Actor. In this second and final part, we will go ahead and implement each of these States. Recap As a quick recap, let’s look at the structure of the FSM and the messages that can be…

Akka Notes - Finite State Machines - 1

I recently had the opportunity to play with Akka FSM at work for some really interesting use-case. The API (in fact, the DSL) is pretty awesome and the entire experience was amazing. Here’s my attempt to log my notes on building a Finite State Machine using Akka FSM. As an example, we’ll walk through the steps of building an (limited) Coffee vending machine. Why not become and unbecome…

Akka Notes - Actor Supervision - 8

Failures are more like a feature among distributed systems. And with Akka’s let it crash fault tolerance model, you could achieve a clear separation between your business logic and your failure handling logic (supervision logic). All with very little effort. It’s pretty amazing. This is the topic of our discussion now. Actor Supervision Imagine a method call stack and the top most…

Akka Notes - DeathWatch - 7

When we talked about Actor lifecycle , we saw that Actors could be stopped by various means (using ActorSystem.stop or ActorContext.stop or sending a PoisonPill - there’s also the Kill and the gracefulStop ). Whatever reason an Actor dies, there are cases when a few other actors in the system would like to know about it. Let’s take a trivial example of an Actor who talks to a database…

Akka Notes - Child Actors and ActorPath - 6

Actors are completely hierarchical. Whatever Actors that you create HAS to be a child of some other Actor. Let’s analyze that a bit : Path Say, we create an ActorRef using ActorSystem.actorOf and try to print its path . 1 2 3 val actorSystem = ActorSystem ( 'SupervisionActorSystem' ) val actorRef = actorSystem . actorOf ( Props [ BasicLifecycleLoggingTeacherActor ]) println ( actorRef . path…

Akka Notes - Actor Lifecycle - Basic - 5

(Please note that this lifecycle write-up does not cover the preRestart or the postRestart methods. We’ll talk about them when we discuss supervision) The basic Actor lifecycle is very much intuitive. You could actually compare the basic Actor lifecycle with a Java servlet lifecycle with one special difference. Just like any other regular class, we have a Constructor The preStart method gets…

Akka Notes - ActorSystem (Configuration and Scheduling) - 4

As we saw from our previous posts, we could create an Actor using the actorOf method of the ActorSystem . There’s actually much more you could do with ActorSystem. We’ll touch upon just the Configuration and the Scheduling bit in this write-up Let’s look at the subsets of methods available in the ActorSystem . Configuration Management Remember the application.conf file we used…

Akka Notes - Actor Messaging - Request and Response - 3

Last time when we saw Actor messaging, we saw how fire-n-forget messages are sent (Meaning, we just send a message to the Actor but don’t expect a response from the Actor). Technically, we fire messages to Actors for its side-effects ALL THE TIME. It is by design. Other than not responding, the target Actor could ALSO do the following with that message - Send a response back to the sender…

Akka Notes - Logging and Testing Actors - 2

In the first two parts ( one , two ), we briefly talked about Actors and how messaging works. In this part, let’s look at fixing up Logging and Testing our TeacherActor . Recap This is how our Actor from the previous part looked like : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 class TeacherActor extends Actor { val quotes = List ( 'Moderation is for cowards' , 'Anything…

Akka Notes - Actor Messaging - 1

From the introductory first part of the Akka Notes, we saw a bird’s eye view of Actors in the Akka Toolkit. In this second part of the Akka Notes, we’ll look at the messaging part of Actors. As for the example, we would use the same Student-Teacher example that we discussed earlier. In this first part of Actor Messaging, we’ll create the Teacher Actor and instead of the Student…

Akka Notes - Introducing Actors

Anyone who has done multithreading in the past won’t deny how hard and painful it is to manage multithreaded applications. I said manage because it starts out simple and it became a whole lot of fun once you start seeing performance improvements. However, it aches when you see that you don’t have a easier way to recover from errors in your sub-tasks OR those zombie bugs that you find…

The Knapsack problem

I found the Knapsack problem tricky and interesting at the same time. I am sure if you are visiting this page, you already know the problem statement but just for the sake of completion : Problem : Given a Knapsack of a maximum capacity of W and N items each with its own value and weight, throw in items inside the Knapsack such that the final contents has the maximum value. Yikes !!! Link to the…

Camel CXF Service with Multiple Query Parameters

While the awesome Apache Camel team is busy fixing the handling of the multiple parameters in the query, here’s a workaround. Hopefully, this post will become obsolete with the next versions of Camel. (Currently, I use 2.7.5) Problem Query parameters more than 1 is passed as a null value into a Camel-CXF service. Say, if the URL has four query parameters as in 1 name = arun & email = arun…

SLF4J binding for ADFLogger - the missing piece

For reasons best left untold, in my day job, I was expected to provide an SLF4J Adapter for ADF Logger Oracle ADF . Not surprisingly, slf4j does not have an adapter for ADFLogger but since ADFLogger was just a gentle wrapper over Java Util Logging, it took a little over an hour to fill that gap. The testcases (more like main programs) in the repository will confirm that the adapter framework plays…

Building Camel-CXF REST Service in OSGi for Karaf - Multicasting and Aggregation

Please check out my other post on building plain CXF services (without Camel) in OSGi on Karaf. This is a basic tutorial on how to create a CXF REST service multicast (and parallelize) the incoming request using Camel source data from two different services aggregate the response and finally return the consolidated result as JSON to the the end user. You could download the entire codebase from…

Building CXF REST Service in OSGi for Karaf

I’ll leave it to the experts to tell how awesome OSGi is . Among the many benefits, I could tell you why we picked up OSGi for a pet project - Modularity, avoiding JAR hell and dynamic updates (hey, why not?) We chose Apache Felix (an OSGi framework specification implementation) and Apache Karaf (ummm, how do I put this - something like an app server for OSGi applications). Besides serving…

Quicksorting - 3-way and Dual Pivot

It’s no news that Quicksort is considered one of the most important algorithms of the century and that it is the defacto system sort for many languages, including the Arrays.sort in Java. So, what’s new about quicksort? Well, nothing except that I figured just now (after 2 damn years of release of Java 7) that the Quicksort implementation of the Arrays.sort has been replaced with a…

Your's deeply - Why Arrays.deepEquals when we have Arrays.equals

While everybody would naturally accept the following lines of code on grounds of reference equality and value equality and that String and wrappers override the equals method, it takes some effort at first to accept the behavior of Arrays.equals and Arrays.deepEquals 1 2 3 4 5 6 7 8 9 10 11 12 Object obj1 = new Object (); Object obj2 = new Object (); String hello1 = new String ( 'hello' ); String…

Evaluating Infix expression - multiple digits

If you are looking for evaluating an infix expression with parantheses, don’t waste your time here. Visit my other fresh write up here These images have been running around Facebook for a while now. Though it is eye-damaging primary level arithmetic , it is kind of sweet to write it as a program. Just for the fun of it, I created an html page driven by a javascript implementation. Here is…

Grokking Geb - Prerequisites

Extremely sorry about the delay on Part 2 of this series. Graduate exams are just round the corner and I am unable to find time for quality research. Exams get over by end of November. I thoroughly enjoy Geb and I think it is the most stylish way to write functional tests. **So, the Prerequisites : ** Some Groovy Magic . Most of all that you need to learn Groovy is covered in this manual but for…

Architexa - A fine code reading tool

I love reading code. For two reasons : If the code is bad, it is an awesome ego boost PLUS you get to foul mouth someone who has a good reputation for designing amazing things. If the code is good, then you get to learn some new tricks and some cool patterns yet to be published anywhere I am sure you read a lot of code and I am sure you’ll love this awesome code reading tool which I came…

A lazy developers introduction to Java Concurrency Executors

I would make a fool out of myself if I tell you that util.concurrent APIs kicks cheetah’s ass when the classes are available since 2004. However, there are some cool features which I would like to revisit. Concurrency experts, now is the time for you to close this window. All others, stay tight for the fun ride. Thou shall not forget your roots Executor is the root interface with a single…

What does java.util.concurrent.Future hold?

Let’s be sure of what the Future holds Future , which is a part of the Java concurrency Task execution framework, is the result of your computation as the javadoc claims. And more. When you are executing a task in a different thread, there is a lot of information you would need from it soon after you submit it to the pool. What can the Future give? Result : If you are spawning multiple…

Callable vs Runnable - The brawl of the runners

Runnable : I am the Yoda of multithreading. For generations, I was the only way (other than lang.Thread) that people could do parallel activities in Java. Remember the cool method that I have - run . Too bad, it returns a void though. Callable : I am a Runnable, just better and cooler. I have this amazing method called call which returns the result of my work. The return type of call is a cool…

Filter lines in log file with ERROR

A couple of days ago, a friend of mine was interested to know how to filter a log file (in my case a log4j log file) for ERRORs alone. An hour of tricks sharing followed and here is the gist of the conversation that you will be interested in. Find me wherever I am Listing all the lines in the log file which has occurrences of ERROR is as simple as executing the following command 1 grep 'ERROR'…

Find Continuous subarray with maximum sum problem - Kadane's algorithm

Update : Previous version of the code failed for some inputs, as pointed out by @Thinker in the first comment. Changes to the program and the presentation were made. Tested to satisfy most conditions that I could google for. In a desperate attempt to increase my sad looking stackoverflow reputation, I replied to an old but interesting problem . The problem goes like this : Given Random integers in…

Heap datastructure in pictures

A binary heap (generally referred as heap) is a rooted left-complete binary tree which has two properties 1 2 3 1) heap property 2) shape property Wow. Now, that is a lot of jargon. Let’s see what each word in the definition means. What is a tree? A tree is just a set of nodes connected by edges. Yikes ! Let’s put this in a picture What is a binary tree? A binary tree is simply a tree…

Quicksort - the easy way

Note : For 3-way partition and Dual Pivot Quicksort (with programs to trace the sort process), please refer to this recent post . Quick sort is the fastest known non-hybrid comparision sort for arrays which has no knowledge of the data beforehand. To top it, it could be done in-place for arrays. For Linked Lists, Merge Sort might be a better option. Also since Quicksort improves its performance by…

Testing automation with Selenium

Never send a human to do a machine’s job Testing a CRM application which I am part of became very difficult over the recent months. There were simply too many usecases. Despite unit testing on the backend services (SOA), bugs crept in on a regular basis considering a lot of logic is on the javascript and other layers of the application. This is Part 1 of this series explaining how the following…