Skip to content

Instantly share code, notes, and snippets.

@maycuatroi1
maycuatroi1 / gist:4cc7d64eec68fa2e919559cfa49715d2
Last active February 6, 2026 07:01
[DeepSeek OCR 2] Pseudo-code from paper concept
# Pseudo-code from paper concept
class DeepEncoderV2:
def forward(self, visual_tokens):
# visual_tokens: [B, m, d] - m tokens, d=896 dim
# Append learnable queries (same count as visual tokens)
queries = self.learnable_queries # [n, d] where n = m
combined = concat([visual_tokens, queries], dim=1) # [B, 2m, d]
# Mixed attention: visual=bidirectional, queries=causal
from transformers import AutoModel, AutoTokenizer
import torch
model_name = 'deepseek-ai/DeepSeek-OCR-2'
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
_attn_implementation='flash_attention_2',
def uoc_chung_lon_nhat(a, b):
while b:
a, b = b, a % b
return a
def nghich_dao_modulo(e, phi):
def extended_gcd(a, b):
if a == 0:
return b, 0, 1
gcd, x1, y1 = extended_gcd(b % a, a)
public class RadixSort {
public static void radixSort(int[] arr) {
if (arr.length == 0) {
return;
}
// Find the maximum number to know number of digits
int max = getMax(arr);
import java.util.ArrayList;
import java.util.Collections;
public class BucketSort {
public static void bucketSort(int[] arr) {
if (arr.length == 0) {
return;
}
public class HeapSort {
public static void heapSort(int[] arr) {
int n = arr.length;
// Build max heap (rearrange array)
for (int i = n / 2 - 1; i >= 0; i--) {
heapify(arr, n, i);
}
public class BubbleSort {
public static void bubbleSort(int[] arr) {
int n = arr.length;
boolean swapped;
for (int i = 0; i < n - 1; i++) {
swapped = false;
for (int j = 0; j < n - i - 1; j++) {
// https://www.youtube.com/watch?v=WYrMGRJ9qFE
public class MergeSort {
// Gộp 2 mảng con đã được sắp xếp
public static void merge(int[] arr, int left, int mid, int right) {
// tính kích thước 2 mảng con
int n1 = mid - left + 1; // Array trái
int n2 = right - mid; // Array phải
// Tạo mảng tạm
public class MergeSort {
// Gộp 2 mảng con đã được sắp xếp
public static void merge(int[] arr, int left, int mid, int right) {
// tính kích thước 2 mảng con
int n1 = mid - left + 1; // Array trái
int n2 = right - mid; // Array phải
// Tạo mảng tạm
int[] L = new int[n1];
int[] R = new int[n2];
// https://www.youtube.com/watch?v=uf_DyA_Ku7A
public class QuickSort {
// Helper method để hoán đổi hai phần tử
private static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}