Skip to content

Instantly share code, notes, and snippets.

View rishabh135's full-sized avatar

Rishabh rishabh135

  • Japan
View GitHub Profile

Introduction: What is DSPy?

Introduction: What is DSPy?

DSPy is a declarative Python framework for building modular, maintainable, and portable AI systems. Unlike traditional prompt engineering, DSPy lets you compose AI software from natural-language modules and structured code, enabling fast iteration and robust integration with a wide range of language models (LMs) and learning strategies.

Key Concepts

  • Declarative AI Programming: Write modular, structured code instead of brittle prompt strings.
@rishabh135
rishabh135 / grpo_demo.py
Created March 13, 2025 21:22 — forked from willccbb/grpo_demo.py
GRPO Llama-1B
# train_grpo.py
#
# See https://github.com/willccbb/verifiers for ongoing developments
#
import re
import torch
from datasets import load_dataset, Dataset
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import LoraConfig
from trl import GRPOConfig, GRPOTrainer
@rishabh135
rishabh135 / merge_attention.py
Created February 17, 2025 06:13 — forked from Chillee/merge_attention.py
Merge Attention
import torch
from torch.nn.attention.flex_attention import create_block_mask, flex_attention
torch.set_default_device('cuda')
q, k, v = [torch.randn(8, 8, 1024, 64, requires_grad=True) for _ in range(3)]
causal_mask = create_block_mask(lambda b, h, q_idx, kv_idx: q_idx >= kv_idx, None, None, 1024, 1024)
uncausal_mask = create_block_mask(lambda b, h, q_idx, kv_idx: q_idx < kv_idx, None, None, 1024, 1024)
ref_out = flex_attention(q, k, v)
causal_out, causal_lse = flex_attention(q, k, v, block_mask=causal_mask, return_lse=True)
@rishabh135
rishabh135 / r1.py
Created February 13, 2025 21:20 — forked from vgel/r1.py
script to run deepseek-r1 with a min-thinking-tokens parameter, replacing </think> with a random continuation string to extend the model's chain of thought
import argparse
import random
import sys
from transformers import AutoModelForCausalLM, AutoTokenizer, DynamicCache
import torch
parser = argparse.ArgumentParser()
parser.add_argument("question", type=str)
parser.add_argument(
import numpy as np
import pandas as pd
import statsmodels.api as sm
import statsmodels.formula.api as smf
import matplotlib.pyplot as plt
# Function to simulate returns and signal
def simulate_returns_and_signal(m_symbols, n_samples, seed):
# Parameters
r = 0 # Average return
@rishabh135
rishabh135 / graphcast_working_inference.py
Created September 27, 2024 16:33
graphcast_working_inference for my project
import argparse
import dataclasses
import functools
import json
import logging
import math
import os
import re
import time
@rishabh135
rishabh135 / mcts_jax.py
Created September 18, 2024 15:51
JAX_mcts_codebase
from typing import Tuple
import jax
import jax.numpy as jnp
import chex
from model import xmr_early_exit
from draft_model import xmr_early_exit as sml_xmr_early_exit
# feed-forward function for reward and value prediction networks
def mlp(x: jax.Array, w1: jax.Array, w2: jax.Array, w3: jax.Array) -> jax.Array:
@rishabh135
rishabh135 / NVIDIA_reranker_output.log
Created August 2, 2024 13:20
nvidia reranker script public output
08/01/2024 15:26:03 - WARNING - root - $$$$ Type: <class 'list'> <class 'langchain_core.documents.base.Document'> Total Documents: 119
08/01/2024 15:26:10 - WARNING - root - ############# Starting the base retrieval ###############################
08/01/2024 15:26:11 - INFO - root - Document 1:
Reasoning CLEVR, NLVR, VisualMRC
Translation Multi30k
VQA ActivityNet-QA, DocVQA, GQA, iVQA,
MSRVTT-QA, MSVD-QA, OCR-VQA, ST-
VQA, ViQuAE, VQAv2, Visual Dialog
Table 10. The SFT blend we used during the ablation study.
@rishabh135
rishabh135 / gff_jina_reranker.py
Created August 2, 2024 01:30
jinaai_reranker_langchain
import os
import requests
import numpy as np
import logging
from datetime import datetime, timedelta
import json
import logging
import asyncio
import time
import concurrent.futures
@rishabh135
rishabh135 / nvidia_reranker.py
Last active August 2, 2024 00:08
nvidia_reranker with working for a local pdf and pretty print in a log for example
from langchain_community.document_loaders import PyPDFLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import FAISS
import os
import requests
import numpy as np
import faiss
from mistralai.client import MistralClient
from mistralai.models.chat_completion import ChatMessage