<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pratik wayase</title>
    <description>The latest articles on DEV Community by pratik wayase (@pratikwayase).</description>
    <link>https://dev.to/pratikwayase</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1179089%2F73dc0fa9-6bbb-429e-b693-97012debd822.png</url>
      <title>DEV Community: pratik wayase</title>
      <link>https://dev.to/pratikwayase</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pratikwayase"/>
    <language>en</language>
    <item>
      <title>thread safe pub - sub</title>
      <dc:creator>pratik wayase</dc:creator>
      <pubDate>Fri, 09 May 2025 10:17:13 +0000</pubDate>
      <link>https://dev.to/pratikwayase/thread-safe-pub-sub-a4l</link>
      <guid>https://dev.to/pratikwayase/thread-safe-pub-sub-a4l</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import java.util.concurrent.*;
import java.util.function.Consumer;

public class AdvancedEventBus {
    private final ConcurrentHashMap&amp;lt;String, CopyOnWriteArraySet&amp;lt;Consumer&amp;lt;Object&amp;gt;&amp;gt;&amp;gt; topicSubscribers = 
        new ConcurrentHashMap&amp;lt;&amp;gt;();
    private final Executor executor;

    public AdvancedEventBus(Executor executor) {
        this.executor = executor != null ? executor : Runnable::run;
    }

    public AdvancedEventBus() {
        this(ForkJoinPool.commonPool());
    }

    public void subscribe(String topic, Consumer&amp;lt;Object&amp;gt; subscriber) {
        topicSubscribers.computeIfAbsent(topic, k -&amp;gt; new CopyOnWriteArraySet&amp;lt;&amp;gt;()).add(subscriber);
    }

    public void unsubscribe(String topic, Consumer&amp;lt;Object&amp;gt; subscriber) {
        topicSubscribers.computeIfPresent(topic, (k, v) -&amp;gt; {
            v.remove(subscriber);
            return v.isEmpty() ? null : v;
        });
    }

    public void publish(String topic, Object message) {
        CopyOnWriteArraySet&amp;lt;Consumer&amp;lt;Object&amp;gt;&amp;gt; subscribers = topicSubscribers.get(topic);
        if (subscribers != null) {
            subscribers.forEach(subscriber -&amp;gt; 
                executor.execute(() -&amp;gt; {
                    try {
                        subscriber.accept(message);
                    } catch (Exception e) {
                        System.err.println("Error in subscriber for topic " + topic + ": " + e.getMessage());
                    }
                })
            );
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ConcurrentHashMap: Used for storing topic-subscriber mappings to ensure thread-safe access&lt;/p&gt;

&lt;p&gt;CopyOnWriteArraySet: Used for subscriber lists to allow safe iteration while subscribers can be added/removed&lt;/p&gt;

&lt;p&gt;Executor: In the advanced version, allows control over how subscriber callbacks are executed&lt;/p&gt;

&lt;p&gt;Atomic operations: Methods like computeIfAbsent ensure atomic updates to the data structures&lt;/p&gt;

&lt;p&gt;example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class PubSubExample {
    public static void main(String[] args) {
        EventBus eventBus = new EventBus();

        // Create subscribers
        Consumer&amp;lt;Object&amp;gt; subscriber1 = message -&amp;gt; 
            System.out.println("Subscriber1 received: " + message);
        Consumer&amp;lt;Object&amp;gt; subscriber2 = message -&amp;gt; 
            System.out.println("Subscriber2 received: " + message);

        // Subscribe to topics
        eventBus.subscribe("news", subscriber1);
        eventBus.subscribe("news", subscriber2);
        eventBus.subscribe("weather", subscriber1);

        // Publish messages
        eventBus.publish("news", "Latest headlines...");
        eventBus.publish("weather", "Sunny today!");

        // Unsubscribe
        eventBus.unsubscribe("news", subscriber2);
        eventBus.publish("news", "Breaking news!");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>webdev</category>
      <category>java</category>
      <category>coding</category>
    </item>
    <item>
      <title>Mixture-of-Agents Enhances Large Language Model Capabilities✨</title>
      <dc:creator>pratik wayase</dc:creator>
      <pubDate>Tue, 18 Jun 2024 14:35:34 +0000</pubDate>
      <link>https://dev.to/pratikwayase/mixture-of-agents-enhances-large-language-model-capabilities-1938</link>
      <guid>https://dev.to/pratikwayase/mixture-of-agents-enhances-large-language-model-capabilities-1938</guid>
      <description>&lt;p&gt;does not require any fine-tuning and only utilizes the interface for prompting and generation of LLMs.&lt;/p&gt;

&lt;p&gt;we do not need to concatenate prompt and all model responses so only one LLM is needed to be used in the last layer. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnrkxl7p9wygo5u18fdq7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnrkxl7p9wygo5u18fdq7.png" alt="llm" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;⚡ design of Mixture-of-Agents.&lt;/p&gt;

&lt;p&gt;2 parts : proposers &amp;amp; aggregators&lt;/p&gt;

&lt;p&gt;Proposers : generating useful reference responses for use by other models. While the proposer may not necessarily produce responses with high scores by itself, it should offer more context and diverse perspectives, ultimately contributing to better final responses when used by an aggregator&lt;/p&gt;

&lt;p&gt;Aggregators : synthesizing responses from other models into a single, high-quality output. An effective aggregator should maintain or integrate inputs that are of lesser quality than its own.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83fccl0zybvn822hi3by.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F83fccl0zybvn822hi3by.png" alt="model perform" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By incorporating more aggregators into the process, we can iteratively synthesize and refine the responses, leveraging the strengths of multiple models to produce superior outcomes.&lt;/p&gt;

&lt;p&gt;Initially, LLMs in the first layer, denoted as agents A1,1,...A1,n, independently generate responses to a given prompt. These responses are then presented to agents in the next layer (A2, 1,... A2, n) for further refinement. &lt;/p&gt;

&lt;p&gt;This iterative refinement process continues for several cycles until a more robust and comprehensive response is obtained.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vip5t8ixlehilkfd4ag.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3vip5t8ixlehilkfd4ag.png" alt="evaluation" width="800" height="1000"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The selection of LLMs for each MoA requires two primary criteria:&lt;/p&gt;

&lt;p&gt;Performance Metrics: The average win rate of models in layer i plays a significant role in determining their suitability for inclusion in layer i + 1.&lt;/p&gt;

&lt;p&gt;Diversity Considerations: The diversity of model outputs is also crucial. Responses generated by heterogeneous models contribute significantly more than those produced by the same model &lt;/p&gt;

&lt;p&gt;By leveraging these criteria — performance and diversity — MoA aims to mitigate individual model deficiencies and enhance overall response quality through collaborative synthesis.&lt;/p&gt;

&lt;p&gt;⚡limitations :&lt;/p&gt;

&lt;p&gt;model cannot decide the first token until the last MoA layer is reached. This potentially results in a high Time to First Token (TTFT), which can negatively impact user experience. &lt;/p&gt;

&lt;p&gt;To mitigate this issue, we can limit the number of MoA layers, as the first response aggregation has the most significant boost on generation quality. &lt;/p&gt;

&lt;h1&gt;
  
  
  llm #datascience #machinelearning
&lt;/h1&gt;

</description>
      <category>llm</category>
      <category>datascience</category>
      <category>machinelearning</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
