Text Generation
Transformers
Safetensors
English
llama
hand-crafted
compiled
autocomplete
no-training
n-gram
code
browser
text-generation-inference
Instructions to use tmickleydoyle/tiny-autocomplete with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tmickleydoyle/tiny-autocomplete with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tmickleydoyle/tiny-autocomplete")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tmickleydoyle/tiny-autocomplete") model = AutoModelForCausalLM.from_pretrained("tmickleydoyle/tiny-autocomplete", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tmickleydoyle/tiny-autocomplete with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tmickleydoyle/tiny-autocomplete" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tmickleydoyle/tiny-autocomplete", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/tmickleydoyle/tiny-autocomplete
- SGLang
How to use tmickleydoyle/tiny-autocomplete with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tmickleydoyle/tiny-autocomplete" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tmickleydoyle/tiny-autocomplete", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tmickleydoyle/tiny-autocomplete" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tmickleydoyle/tiny-autocomplete", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use tmickleydoyle/tiny-autocomplete with Docker Model Runner:
docker model run hf.co/tmickleydoyle/tiny-autocomplete
File size: 6,183 Bytes
4113449 | 1 2 | function T(){let H=[];for(let q=33;q<=126;q++)H.push(q);for(let q=161;q<=172;q++)H.push(q);for(let q=174;q<=255;q++)H.push(q);let J=[...H],D=0;for(let q=0;q<256;q++)if(!H.includes(q))H.push(q),J.push(256+D++);return new Map(H.map((q,K)=>[q,String.fromCodePoint(J[K])]))}var $=T(),w=new Map([...$].map(([H,J])=>[J,H])),C=/'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu,j=new TextEncoder,y=new TextDecoder;function v(H){let J=H.normalize("NFKC").toLowerCase();if(J&&!/^\s/.test(J))J=" "+J;return(J.match(C)??[]).map((D)=>[...j.encode(D)].map((q)=>$.get(q)).join(""))}function W(H){return y.decode(new Uint8Array([...H].map((J)=>w.get(J)??63)))}var g="TACB";class Y{vocab;nPrev;order;eosId;unkId;policy;bytes;contexts;text;pieceIndex;base;orders;oov;stopAfter;candCache=new Map;distCache=new Map;static async load(H,J){if(H instanceof ArrayBuffer)return new Y(H);let D=await fetch(H);if(!D.ok||!D.body)throw Error(`failed to fetch ${H}: ${D.status}`);let q=Number(D.headers.get("content-length"))||0,K=D.body.getReader(),O=[],R=0;for(;;){let{done:X,value:Z}=await K.read();if(X)break;if(O.push(Z),R+=Z.length,q)J?.(R/q)}let U=new Uint8Array(R),F=0;for(let X of O)U.set(X,F),F+=X.length;return J?.(1),new Y(U.buffer)}constructor(H){let J=new DataView(H);if(new TextDecoder().decode(new Uint8Array(H,0,4))!==g)throw Error("not a tiny-autocomplete model.bin");let q=J.getUint32(8,!0),K=JSON.parse(new TextDecoder().decode(new Uint8Array(H,12,q))),O=12+q+(8-(12+q)%8)%8,R=new Map;for(let V of K.sections)R.set(V.name,V);let U=K.id_bytes===2?Uint16Array:Uint32Array,F=(V)=>{let Q=R.get(V);return new Float32Array(H,O+Q.offset,Q.bytes/4)},X=(V)=>{let Q=R.get(V);return new Uint32Array(H,O+Q.offset,Q.bytes/4)},Z=(V)=>{let Q=R.get(V);return new U(H,O+Q.offset,Q.bytes/K.id_bytes)};this.vocab=K.vocab,this.text=this.vocab.map((V)=>W(V)),this.pieceIndex=new Map(this.vocab.map((V,Q)=>[V,Q])),this.nPrev=K.n_prev,this.order=this.nPrev+1,this.eosId=K.eos_id,this.unkId=K.unk_id,this.oov=K.oov_prefix_rates,this.policy=K.policy,this.stopAfter=new Set(K.stop_after),this.bytes=H.byteLength,this.base=F("base"),this.orders=K.orders.map(({k:V,contexts:Q})=>{let M=Z(`ctx${V}`),L=new Map;for(let B=0;B<Q;B++)L.set(M.subarray(B*V,(B+1)*V).join(","),B);return{k:V,ctx:M,support:F(`support${V}`),offsets:X(`offsets${V}`),dids:Z(`dids${V}`),dvals:F(`dvals${V}`),index:L}}),this.contexts=this.orders.reduce((V,Q)=>V+Q.index.size,0)}window(H){let J=H.length-1,D=[];for(let q=this.nPrev;q>=0;q--)D.push(H[Math.max(J-q,0)]);return D}dist(H){let J=this.window(H),D=J.join(","),q=this.distCache.get(D);if(q)return q;let K=Float64Array.from(this.base),O=0;for(let Z of this.orders){let V=Z.index.get(J.slice(-Z.k).join(","));if(V===void 0)continue;for(let Q=Z.offsets[V];Q<Z.offsets[V+1];Q++)K[Z.dids[Q]]+=Z.dvals[Q];O=Z.support[V]}let R=-1/0;for(let Z of K)if(Z>R)R=Z;let U=0,F=new Float64Array(K.length);for(let Z=0;Z<K.length;Z++)U+=F[Z]=Math.exp(K[Z]-R);for(let Z=0;Z<F.length;Z++)F[Z]/=U;if(this.distCache.size>2000)this.distCache.clear();let X={probs:F,support:O};return this.distCache.set(D,X),X}candidates(H){let J=this.candCache.get(H);if(!J){let D=[];for(let q=this.unkId+1;q<this.vocab.length;q++)if(this.vocab[q].startsWith(H))D.push(q);if(J=Int32Array.from(D),this.candCache.size>5000)this.candCache.clear();this.candCache.set(H,J)}return J}steps(H,J=this.policy.max_words){let D=v(H);if(!D.length)return[];let q=D[D.length-1],K=this.candidates(q);if(!K.length)return[];let O=[this.eosId,...D.slice(0,-1).map((Q)=>this.pieceIndex.get(Q)??this.unkId)],{probs:R,support:U}=this.dist(O),F=K[0],X=0;for(let Q of K)if(X+=R[Q],R[Q]>R[F])F=Q;let Z=(1-(this.oov[q]??0))*(R[F]/X),V=[{text:this.text[F].slice(W(q).length),prob:Z,support:U}];O.push(F);while(!this.stopAfter.has(this.vocab[O[O.length-1]])&&V.length<J){({probs:R,support:U}=this.dist(O));let Q=0;for(let M=1;M<R.length;M++)if(R[M]>R[Q])Q=M;if(Q===this.eosId)break;Z*=R[Q],V.push({text:this.text[Q],prob:Z,support:U}),O.push(Q)}return V}static apply(H,J){let D="",q=0;for(let K of H.slice(0,J.max_words)){if(K.prob<J.tau||K.support<J.min_support)break;D+=K.text,q=K.prob}return{ghost:D,prob:q}}suggest(H,J=this.policy){let D=this.steps(H,J.max_words);return{...Y.apply(D,J),steps:D}}}var G=(H)=>document.getElementById(H),N=G("prompt"),z=G("ghost"),f=G("status"),_=G("guess"),S=G("tau"),A=G("tau-label"),I=G("load"),k=["write a python fun","how do i ","Write a function to find the ","how to convert a ","can you explain ","I hope this email ","Once upon a ","what is the difference between "];function P(H){return H.replace(/[&<>]/g,(J)=>({"&":"&","<":"<",">":">"})[J])}async function E(){let H=performance.now(),J=await Y.load("model.bin",(R)=>I.textContent=`downloading model... ${Math.round(R*100)}%`),D=performance.now()-H,q={...J.policy};S.value=String(q.tau),A.textContent=`${Math.round(q.tau*100)}%`,I.textContent=`${(J.bytes/1e6).toFixed(1)} MB 路 ${J.contexts.toLocaleString()} compiled contexts 路 `+`${J.order}-token context 路 ${J.vocab.length.toLocaleString()} words 路 loaded in ${Math.round(D)} ms`,N.disabled=!1,N.focus();let K="",O=()=>{let R=N.value,U=performance.now(),F=J.suggest(R,q),X=performance.now()-U;K=F.ghost,z.innerHTML=P(R)+"<span>"+P(K)+"</span>",N.style.height="auto",N.style.height=Math.max(N.scrollHeight,z.scrollHeight)+"px",f.textContent=R?`${X.toFixed(2)} ms`:"";let Z=F.steps.findIndex((Q)=>Q.text),V=Z<0?"":F.steps.slice(0,Z+1).map((Q)=>Q.text).join("");if(!R)_.textContent="";else if(K)_.textContent=`suggesting with ${Math.round(F.prob*100)}% confidence`;else if(V)_.textContent=`staying quiet: best guess "${V}" is only ${Math.round(F.steps[Z].prob*100)}% likely`;else _.textContent="staying quiet: nothing known for this prefix"};N.addEventListener("input",O),N.addEventListener("keydown",(R)=>{if(R.key==="Tab"&&K)R.preventDefault(),N.value+=K,O()}),S.addEventListener("input",()=>{q.tau=Number(S.value),A.textContent=`${Math.round(q.tau*100)}%`,O()});for(let R of k){let U=document.createElement("button");U.className="ex",U.textContent=R.trim(),U.onclick=()=>{N.value=R,O(),N.focus()},G("examples").appendChild(U)}O()}E().catch((H)=>I.textContent=String(H));
|