<?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: Sudhanshu Shukla</title>
    <description>The latest articles on DEV Community by Sudhanshu Shukla (@sudhanshu_shukla_b32404a1).</description>
    <link>https://dev.to/sudhanshu_shukla_b32404a1</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4245976%2F2762e723-30bc-4ac9-844d-4cda66822208.jpg</url>
      <title>DEV Community: Sudhanshu Shukla</title>
      <link>https://dev.to/sudhanshu_shukla_b32404a1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sudhanshu_shukla_b32404a1"/>
    <language>en</language>
    <item>
      <title>Training a Small GPT-Style Language Model from Scratch with PyTorch, Hugging Face, and CUDA</title>
      <dc:creator>Sudhanshu Shukla</dc:creator>
      <pubDate>Mon, 16 Nov 2026 18:47:10 +0000</pubDate>
      <link>https://dev.to/sudhanshu_shukla_b32404a1/training-a-small-gpt-style-language-model-from-scratch-with-pytorch-hugging-face-and-cuda-5co</link>
      <guid>https://dev.to/sudhanshu_shukla_b32404a1/training-a-small-gpt-style-language-model-from-scratch-with-pytorch-hugging-face-and-cuda-5co</guid>
      <description>&lt;p&gt;Introduction&lt;/p&gt;

&lt;p&gt;Understanding large language models becomes much more practical when you move beyond loading pretrained checkpoints and explore the training process yourself.&lt;/p&gt;

&lt;p&gt;I recently extended a PyTorch Transformer project with a generative language-model training workflow using Hugging Face Datasets, Tokenizers, Transformers, and CUDA.&lt;/p&gt;

&lt;p&gt;The result is a small, approximately 1.06-million-parameter GPT-style causal language model trained on a subset of TinyStories.&lt;/p&gt;

&lt;p&gt;This article documents the architecture, training pipeline, model serialization, experimental results, and limitations.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Architecture and technology stack&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The project contains two distinct Transformer workflows:&lt;/p&gt;

&lt;p&gt;A custom PyTorch Transformer encoder for binary text classification.&lt;/p&gt;

&lt;p&gt;A new decoder-only GPT-style causal language model for next-token prediction.&lt;/p&gt;

&lt;p&gt;The generative model uses Hugging Face's GPT2Config and GPT2LMHeadModel, initialized with random weights rather than pretrained GPT-2 weights.&lt;/p&gt;

&lt;p&gt;Technology stack&lt;/p&gt;

&lt;p&gt;Python and PyTorch&lt;/p&gt;

&lt;p&gt;Hugging Face Transformers&lt;/p&gt;

&lt;p&gt;Hugging Face Datasets&lt;/p&gt;

&lt;p&gt;Hugging Face Tokenizers&lt;/p&gt;

&lt;p&gt;NVIDIA CUDA&lt;/p&gt;

&lt;p&gt;AdamW optimizer&lt;/p&gt;

&lt;p&gt;Safetensors and Hugging Face Hub&lt;/p&gt;

&lt;p&gt;The experimental configuration uses three decoder layers, four attention heads, a hidden dimension of 128, and a maximum context length of 128 tokens.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Hugging Face dataset integration&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I used the TinyStories dataset, available at:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://huggingface.co/datasets/roneneldan/TinyStories" rel="noopener noreferrer"&gt;https://huggingface.co/datasets/roneneldan/TinyStories&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The pipeline loads examples using Hugging Face Datasets streaming, filters unusable text, shuffles the selected corpus, and divides the samples into training and validation sets.&lt;/p&gt;

&lt;p&gt;For this run, I used:&lt;/p&gt;

&lt;p&gt;270 training records&lt;/p&gt;

&lt;p&gt;30 validation records&lt;/p&gt;

&lt;p&gt;A fixed random seed&lt;/p&gt;

&lt;p&gt;This deliberately small corpus was selected to validate the end-to-end implementation rather than to produce a capable general-purpose language model.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Training a tokenizer&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The pipeline trains a byte-level BPE tokenizer directly on the training texts.&lt;/p&gt;

&lt;p&gt;It includes padding, unknown, beginning-of-sequence, and end-of-sequence tokens.&lt;/p&gt;

&lt;p&gt;The resulting vocabulary contains 3,512 tokens.&lt;/p&gt;

&lt;p&gt;Training the tokenizer only on the training split keeps the held-out validation texts separate from vocabulary learning.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Creating the GPT-style model&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The model is initialized using Hugging Face's GPT-2 architecture with randomly initialized weights.&lt;/p&gt;

&lt;p&gt;Its essential configuration includes:&lt;/p&gt;

&lt;p&gt;Hidden size: 128&lt;/p&gt;

&lt;p&gt;Decoder layers: 3&lt;/p&gt;

&lt;p&gt;Attention heads: 4&lt;/p&gt;

&lt;p&gt;Context length: 128&lt;/p&gt;

&lt;p&gt;Vocabulary size: 3,512&lt;/p&gt;

&lt;p&gt;Trainable model parameters: 1,060,992&lt;/p&gt;

&lt;p&gt;Unlike an encoder-based classification model, a causal language model predicts subsequent tokens using a causal attention mechanism.&lt;/p&gt;

&lt;p&gt;The training data is tokenized into input sequences with corresponding next-token learning targets, while padding positions are excluded from the loss.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Training and optimization&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Training runs on an NVIDIA GPU through PyTorch CUDA.&lt;/p&gt;

&lt;p&gt;The workflow uses AdamW, cross-entropy-based causal language-model loss, gradient clipping, and validation after each epoch.&lt;/p&gt;

&lt;p&gt;The best-performing checkpoint is selected using validation loss.&lt;/p&gt;

&lt;p&gt;Training results&lt;/p&gt;

&lt;p&gt;Metric&lt;/p&gt;

&lt;p&gt;Epoch 1&lt;/p&gt;

&lt;p&gt;Epoch 2&lt;/p&gt;

&lt;p&gt;Training loss&lt;/p&gt;

&lt;p&gt;7.5319&lt;/p&gt;

&lt;p&gt;6.6421&lt;/p&gt;

&lt;p&gt;Validation loss&lt;/p&gt;

&lt;p&gt;7.0656&lt;/p&gt;

&lt;p&gt;6.3688&lt;/p&gt;

&lt;p&gt;Both reported losses decreased during the two-epoch experiment.&lt;/p&gt;

&lt;p&gt;These are preliminary results, not evidence of general-purpose language understanding or performance on standardized language-model benchmarks.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Saving and reloading the model&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The training program exports the model configuration, tokenizer, and weights into a directory compatible with Hugging Face Transformers.&lt;/p&gt;

&lt;p&gt;The saved model was successfully reloaded using AutoModelForCausalLM.from_pretrained() and AutoTokenizer.from_pretrained().&lt;/p&gt;

&lt;p&gt;The generated text is still repetitive and grammatically inconsistent, which is expected given the small model capacity and extremely limited training.&lt;/p&gt;

&lt;p&gt;Nevertheless, the experiment validates the complete technical path from dataset ingestion through inference.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Lessons learned&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Tokenizer design matters. Vocabulary size and tokenization affect sequence representation and the model's output space.&lt;/p&gt;

&lt;p&gt;Architecture matters. A Transformer encoder designed for classification is not directly interchangeable with a decoder-only generative model.&lt;/p&gt;

&lt;p&gt;Validation matters. Saving the checkpoint with the lowest validation loss provides a more useful selection criterion than relying solely on training loss.&lt;/p&gt;

&lt;p&gt;GPU memory matters. Smaller architectures, shorter contexts, and conservative batch sizes make experimentation possible on consumer hardware.&lt;/p&gt;

&lt;p&gt;Reproducibility matters. Model configurations, tokenizer files, dependency information, dataset provenance, and known limitations should be documented.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Next experiments&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;My next development priorities include:&lt;/p&gt;

&lt;p&gt;Increasing training data and token coverage.&lt;/p&gt;

&lt;p&gt;Comparing model depth, hidden dimensions, and context lengths.&lt;/p&gt;

&lt;p&gt;Adding held-out perplexity and generation-quality evaluation.&lt;/p&gt;

&lt;p&gt;Measuring GPU memory consumption and training throughput.&lt;/p&gt;

&lt;p&gt;Exploring mixed-precision training and memory-efficient attention where hardware supports them.&lt;/p&gt;

&lt;p&gt;Improving model documentation and reproducibility.&lt;/p&gt;

&lt;p&gt;Conclusion&lt;/p&gt;

&lt;p&gt;This experiment helped connect Transformer architecture concepts with the practical workflow of training a generative language model.&lt;/p&gt;

&lt;p&gt;The current checkpoint is a small proof of concept, not a production-grade model. Its value is in demonstrating the engineering steps required to create, validate, save, and reload a causal language model.&lt;/p&gt;

&lt;p&gt;Hugging Face model:&lt;br&gt;
&lt;a href="https://huggingface.co/sudhanshu42844/my-tiny-llm" rel="noopener noreferrer"&gt;https://huggingface.co/sudhanshu42844/my-tiny-llm&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Feedback on the training pipeline, model evaluation, and efficient experimentation with small language models is welcome.&lt;/p&gt;

</description>
      <category>python</category>
      <category>deeplearning</category>
      <category>pytorch</category>
    </item>
    <item>
      <title>Building Across the AI Stack: RAG, LangChain, LangGraph Agents, LLM Fine-Tuning and Distributed Inference</title>
      <dc:creator>Sudhanshu Shukla</dc:creator>
      <pubDate>Sun, 15 Nov 2026 13:16:14 +0000</pubDate>
      <link>https://dev.to/sudhanshu_shukla_b32404a1/building-across-the-ai-stack-rag-langchain-langgraph-agents-llm-fine-tuning-and-distributed-3ef4</link>
      <guid>https://dev.to/sudhanshu_shukla_b32404a1/building-across-the-ai-stack-rag-langchain-langgraph-agents-llm-fine-tuning-and-distributed-3ef4</guid>
      <description>&lt;h1&gt;
  
  
  Building Across the AI Stack: RAG, LangGraph Agents, LLM Fine-Tuning and Distributed Inference
&lt;/h1&gt;

&lt;p&gt;AI engineering involves more than connecting an LLM to an API. Building reliable AI applications requires an understanding of retrieval, model behavior, training techniques, orchestration, and inference infrastructure.&lt;/p&gt;

&lt;p&gt;I've organized nine public projects to explore these areas through source code, implementation examples, and technical documentation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Portfolio:&lt;/strong&gt; &lt;a href="https://su394611-del.github.io/" rel="noopener noreferrer"&gt;https://su394611-del.github.io/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Retrieval-Augmented Generation and Information Retrieval
&lt;/h2&gt;

&lt;p&gt;Retrieval systems introduce architectural decisions that affect relevance, security, and response quality.&lt;/p&gt;

&lt;p&gt;Some important design considerations include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Selecting embedding models and vector databases.&lt;/li&gt;
&lt;li&gt;Maintaining tenant-specific retrieval boundaries.&lt;/li&gt;
&lt;li&gt;Designing retrieval APIs with FastAPI.&lt;/li&gt;
&lt;li&gt;Implementing caching without compromising data isolation.&lt;/li&gt;
&lt;li&gt;Evaluating retrieval quality independently of language generation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My &lt;a href="https://su394611-del.github.io/RAG-service/" rel="noopener noreferrer"&gt;RAG Service&lt;/a&gt; explores FastAPI, Qdrant, tenant-scoped retrieval, and semantic caching.&lt;/p&gt;

&lt;p&gt;A particularly important distinction is between retrieving relevant information and generating grounded answers. Evaluate retrieval quality before attributing improvements to the language model itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Agentic AI with LangGraph
&lt;/h2&gt;

&lt;p&gt;AI agents need more than prompting. They require controlled execution, explicit state management, tool integration, and predictable routing.&lt;/p&gt;

&lt;p&gt;My &lt;a href="https://su394611-del.github.io/Mutli-agents-using-LangGraph/" rel="noopener noreferrer"&gt;LangGraph project&lt;/a&gt; explores concepts such as StateGraph, MessagesState, state reducers, Pydantic validation, and reusable subgraphs.&lt;/p&gt;

&lt;p&gt;For agentic systems, I consider three questions especially important:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How should state move between agents?&lt;/li&gt;
&lt;li&gt;How can tool inputs and outputs be validated?&lt;/li&gt;
&lt;li&gt;How should a workflow handle invalid outputs and execution failures?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Graph-based orchestration can make these execution paths easier to reason about and inspect.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. LLM Training and Fine-Tuning
&lt;/h2&gt;

&lt;p&gt;Training and adapting language models introduce trade-offs involving GPU memory, optimization methods, dataset quality, and evaluation.&lt;/p&gt;

&lt;p&gt;The projects explore:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Transformer attention mechanisms and encoder architectures.&lt;/li&gt;
&lt;li&gt;Supervised fine-tuning and LoRA.&lt;/li&gt;
&lt;li&gt;Preference optimization approaches such as DPO and ORPO.&lt;/li&gt;
&lt;li&gt;DistilBERT fine-tuning configurations.&lt;/li&gt;
&lt;li&gt;Distributed training using PyTorch DDP.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href="https://su394611-del.github.io/Pre-training-and-Fine-tuning/" rel="noopener noreferrer"&gt;LLM Fine-Tuning project&lt;/a&gt; provides implementation examples of model adaptation and preference optimization techniques.&lt;/p&gt;

&lt;p&gt;An essential engineering principle is that successful code execution does not automatically establish model quality. Training results need to be evaluated using appropriate datasets, metrics, and reproducible configurations.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Distributed Training and Parallel Inference
&lt;/h2&gt;

&lt;p&gt;Training and inference present different scaling challenges.&lt;/p&gt;

&lt;p&gt;DistributedDataParallel typically synchronizes model gradients during training, while multi-worker inference often uses independent model replicas to process separate workloads.&lt;/p&gt;

&lt;p&gt;The portfolio explores both approaches:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://su394611-del.github.io/Distributed-Data-Parallel-Processing/" rel="noopener noreferrer"&gt;Distributed LLM Training&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://su394611-del.github.io/Parallel-LLM-Inference/" rel="noopener noreferrer"&gt;Parallel LLM Inference&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Important measurement areas include GPU utilization, model-loading overhead, throughput, latency, and memory consumption.&lt;/p&gt;

&lt;p&gt;Implementation examples and performance-validated systems should be distinguished clearly, especially when physical multi-GPU execution has not been demonstrated.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Other Projects in the Collection
&lt;/h2&gt;

&lt;p&gt;The portfolio also includes a Transformer encoder implementation, DistilBERT training comparisons, Transformer evaluation workflows, and an MCP/LangGraph market simulation.&lt;/p&gt;

&lt;p&gt;Together, these projects examine different parts of the AI engineering lifecycle rather than treating LLM integration as a single problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. What I Want to Explore Next
&lt;/h2&gt;

&lt;p&gt;The areas I find especially valuable for further technical investigation include reproducible model evaluation, retrieval benchmarking, agent reliability, GPU performance profiling, and systematic comparisons between training configurations.&lt;/p&gt;

&lt;p&gt;My goal is to make the implementations easier to inspect, reproduce, test, and improve.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explore the Projects
&lt;/h2&gt;

&lt;p&gt;All nine project websites, GitHub repositories, and supporting documentation are linked from the central portfolio:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://su394611-del.github.io/" rel="noopener noreferrer"&gt;https://su394611-del.github.io/&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I welcome technical feedback, architecture discussions, bug reports, and collaboration from other developers working with modern AI systems.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>llm</category>
      <category>rag</category>
    </item>
  </channel>
</rss>
