Run this model with HF Jobs

Run OpenTensorLab/OCRia-1-W4A16-LLM-Compressor on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-LLM-Compressor. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Vishva R
Update model weights, configs, and auxiliary files
d8db4d8 verified
Raw History Blame Contribute Delete
7.41 kB
// Copyright (c) 2026 LlamaIndex, Inc. All rights reserved.
// Licensed under the OCRia-1 Model and Code License (LICENSE at the root of this repository).
// This is not open-source software: see the license for permitted uses.
// Arrays are contiguous float64, int32, or byte booleans, owned by Python.
// Coordinates use attention-grid cells; valid indices retain transcript positions.
// Compile without fused arithmetic to preserve reference feature rounding.
#include <algorithm>
#include <cmath>
#include <vector>
static double median(std::vector<double>& v) {
std::sort(v.begin(),v.end()); const auto n=v.size();
return n%2 ? v[n/2] : (v[n/2-1]+v[n/2])/2.0;
}
extern "C" void neighborhood(int n, int m, const double* xy, const double* lengths,
const int* owner, const int* valid, double* out) {
for (int r=0;r<m;++r) {
const int u=valid[r];const double px=xy[2*u],py=xy[2*u+1];double* row=out+19*r;
const int offsets[4]={-2,-1,1,2};
for(int k=0;k<4;++k) {
const int v=u+offsets[k];
if(v>=0 && v<n && owner[v]==owner[u] && std::isfinite(xy[2*v])) {
row[k*4]=std::clamp(xy[2*v]-px,-20.0,20.0);
row[k*4+1]=std::clamp(xy[2*v+1]-py,-10.0,10.0);
row[k*4+2]=lengths[v];row[k*4+3]=1.0;
} else for(int j=0;j<4;++j)row[k*4+j]=0;
}
std::vector<int> nearby;std::vector<double> ys,adv;
for(int v=std::max(0,u-12);v<std::min(n,u+13);++v)
if(owner[v]==owner[u] && std::isfinite(xy[2*v]) && std::abs(xy[2*v+1]-py)<=1) {
nearby.push_back(v);ys.push_back(xy[2*v+1]);
}
for(size_t k=1;k<nearby.size();++k) {
const int a=nearby[k-1],b=nearby[k];
const double delta=xy[2*b]-xy[2*a];
const double chars=.75*lengths[a]+1+.25*lengths[b];
const double ratio=delta/std::max(chars,1.0);
if(ratio>=.1 && ratio<=1.5)adv.push_back(delta/chars);
}
row[16]=nearby.size();row[17]=adv.empty()?0:median(adv);row[18]=ys.empty()?0:median(ys)-py;
}
}
// Sum neighbors in transcript order to match the reference floating-point order.
extern "C" void pool_profiles(int n, int m, const double* xy, const int* owner,
const int* valid, const int* lookup,
const double* profiles, double* out) {
for(int r=0;r<m;++r) {
const int u=valid[r];double* row=out+8*r;
std::fill(row,row+8,0.0);int count=0;
for(int v=std::max(0,u-12);v<std::min(n,u+13);++v) {
if(v==u || owner[v]!=owner[u] || lookup[v]<0 || std::abs(xy[2*v+1]-xy[2*u+1])>1)continue;
const int offset=static_cast<int>(std::nearbyint(xy[2*v+1]-xy[2*u+1]));
for(int k=0;k<5;++k)row[1+offset+k]+=profiles[5*lookup[v]+k];
++count;
}
if(count)for(int k=0;k<7;++k)row[k]/=count;
row[7]=count;
}
}
// The caller supplies a true seed and a zeroed output mask. Visit only its
// eight-connected component; unrelated components do not need labels.
extern "C" void peak_component_bounds(int h, int w, const unsigned char* mask, int seed,
unsigned char* selected, int* bounds) {
bounds[0]=seed%w; bounds[1]=seed/w;
bounds[2]=bounds[0]+1; bounds[3]=bounds[1]+1;
std::vector<int> queue;queue.push_back(seed);selected[seed]=1;
for(size_t k=0;k<queue.size();++k) {
const int at=queue[k],y=at/w,x=at%w;
bounds[0]=std::min(bounds[0],x); bounds[1]=std::min(bounds[1],y);
bounds[2]=std::max(bounds[2],x+1); bounds[3]=std::max(bounds[3],y+1);
for(int yy=std::max(0,y-1);yy<std::min(h,y+2);++yy)
for(int xx=std::max(0,x-1);xx<std::min(w,x+2);++xx) {
const int j=yy*w+xx;
if(mask[j] && !selected[j]) { selected[j]=1;queue.push_back(j); }
}
}
}
extern "C" void peak_component(int h, int w, const unsigned char* mask, int seed,
unsigned char* selected) {
int bounds[4];
peak_component_bounds(h,w,mask,seed,selected,bounds);
}
#include <cmath>
#include <algorithm>
// Interleave eight independent rows to overlap dependent node loads. Each row
// still accumulates leaves in tree order; the tail handles incomplete groups.
// Compact nodes avoid converting integer links and fit two nodes per cache line.
struct TreeNode {
double value, threshold;
int feature, left, right, flags;
};
static_assert(sizeof(TreeNode)==32);
extern "C" void predict_compact_trees(int rows,int cols,const double* x,int trees,
const int* roots,const TreeNode* nodes,double baseline,double* out) {
std::fill(out,out+rows,baseline);
for(int t=0;t<trees;++t) {
int r=0;
for(;r+7<rows;r+=8) {
int j[8]={roots[t],roots[t],roots[t],roots[t],roots[t],roots[t],roots[t],roots[t]};
bool active=true;
while(active) {
active=false;
for(int k=0;k<8;++k) {
const auto& node=nodes[j[k]];
if(node.flags&2) continue;
active=true;
double v=x[(r+k)*cols+node.feature];
bool left=std::isnan(v)?(node.flags&1)!=0:v<=node.threshold;
j[k]=left?node.left:node.right;
}
}
for(int k=0;k<8;++k) out[r+k]+=nodes[j[k]].value;
}
for(;r<rows;++r) {
int j=roots[t];
while(!(nodes[j].flags&2)) {
const auto& node=nodes[j];
double v=x[r*cols+node.feature];
bool left=std::isnan(v)?(node.flags&1)!=0:v<=node.threshold;
j=left?node.left:node.right;
}
out[r]+=nodes[j].value;
}
}
}
// Eight-connected components in first-cell order, with exclusive right/bottom edges.
#include <vector>
#include <cstdint>
extern "C" int component_boxes(int h,int w,const uint8_t* mask,int* out) {
const int n=h*w;std::vector<uint8_t> seen(n);std::vector<int> q;q.reserve(n);int count=0;
for(int seed=0;seed<n;++seed){
if(!mask[seed]||seen[seed])continue;
q.clear();q.push_back(seed);seen[seed]=1;
int x0=seed%w,x1=x0+1,y0=seed/w,y1=y0+1;
for(size_t k=0;k<q.size();++k){int p=q[k],x=p%w,y=p/w;
if(x<x0)x0=x;if(x+1>x1)x1=x+1;if(y<y0)y0=y;if(y+1>y1)y1=y+1;
for(int dy=-1;dy<=1;++dy)for(int dx=-1;dx<=1;++dx){int nx=x+dx,ny=y+dy;
if(nx<0||nx>=w||ny<0||ny>=h)continue;int j=ny*w+nx;
if(mask[j]&&!seen[j]){seen[j]=1;q.push_back(j);}
}
}
out[count*4]=x0;out[count*4+1]=y0;out[count*4+2]=x1;out[count*4+3]=y1;++count;
}
return count;
}
// Bounds are clipped, nonempty cell-edge rectangles in x0,y0,x1,y1 order.
extern "C" void box_maxima(int width,const double* values,int count,
const int* bounds,double* out) {
for(int k=0;k<count;++k) {
const int* b=bounds+4*k;double maximum=values[b[1]*width+b[0]];
for(int y=b[1];y<b[3];++y) for(int x=b[0];x<b[2];++x) {
double v=values[y*width+x];
if(std::isnan(v)) {maximum=v;y=b[3];break;}
if(v>=maximum)maximum=v;
}
out[k]=maximum;
}
}
// Share marginal sums and cumulative mass across quantile rectangles.
#include <vector>
#include <algorithm>
extern "C" void mass_boxes(int h,int w,const double* v,int count,const double* q,double* out) {
std::vector<double> x(w,0),y(h,0);
for(int r=0;r<h;++r) for(int c=0;c<w;++c){double a=v[r*w+c];x[c]+=a;y[r]+=a;}
for(int c=1;c<w;++c)x[c]+=x[c-1];
for(int r=1;r<h;++r)y[r]+=y[r-1];
for(int k=0;k<count;++k){
out[k*4]=std::upper_bound(x.begin(),x.end(),q[k]*x.back())-x.begin();
out[k*4+1]=std::upper_bound(y.begin(),y.end(),q[k]*y.back())-y.begin();
out[k*4+2]=std::min(w,int(std::lower_bound(x.begin(),x.end(),(1-q[k])*x.back())-x.begin())+1);
out[k*4+3]=std::min(h,int(std::lower_bound(y.begin(),y.end(),(1-q[k])*y.back())-y.begin())+1);
}
}