import{s as al,n as Ml,o as il}from"../chunks/scheduler.56725da7.js";import{S as ml,i as pl,e as c,s as n,c as i,h as ol,a as y,d as e,b as a,f as tl,g as m,j as B,k as nl,l as rl,m as t,n as p,t as o,o as r,p as u}from"../chunks/index.18a26576.js";import{C as ul}from"../chunks/CopyLLMTxtMenu.b9295305.js";import{C as L}from"../chunks/CodeBlock.8f86d875.js";import{H as D}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.61bde07c.js";function cl(P){let M,G,W,S,j,C,J,$,U,K='<a href="https://sbert.net/" rel="nofollow">SentenceTransformers 🤗</a> is a Python framework for state-of-the-art sentence, text and image embeddings. It can be used to compute embeddings using Sentence Transformer models or to calculate similarity scores using Cross-Encoder (a.k.a. reranker) models. This unlocks a wide range of applications, including semantic search, semantic textual similarity, and paraphrase mining. Optimum Neuron offer APIs to ease the use of SentenceTransformers on AWS Neuron devices.',E,b,N,h,q,T,O="<li>Example - Text embeddings</li>",v,d,R,f,ll="<li>Example - Image Search</li>",z,w,A,Z,Q,I,sl="<li>Example - Text embeddings</li>",k,g,x,_,el="<li>Example - Image Search</li>",F,X,H,V,Y;return j=new ul({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),J=new D({props:{title:"Sentence Transformers 🤗",local:"sentence-transformers-",headingTag:"h1"}}),b=new D({props:{title:"Export to Neuron",local:"export-to-neuron",headingTag:"h2"}}),h=new D({props:{title:"Option 1: CLI",local:"option-1-cli",headingTag:"h3"}}),d=new L({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBuZXVyb24lMjAtbSUyMEJBQUklMkZiZ2UtbGFyZ2UtZW4tdjEuNSUyMC0tc2VxdWVuY2VfbGVuZ3RoJTIwMzg0JTIwLS1iYXRjaF9zaXplJTIwMSUyMC0tdGFzayUyMGZlYXR1cmUtZXh0cmFjdGlvbiUyMGJnZV9lbWJfbmV1cm9uJTJG",highlighted:'optimum-cli <span class="hljs-built_in">export</span> neuron -m BAAI/bge-large-en-v1.5 --sequence_length 384 --batch_size 1 --task feature-extraction bge_emb_neuron/',wrap:!1}}),w=new L({props:{code:"b3B0aW11bS1jbGklMjBleHBvcnQlMjBuZXVyb24lMjAtbSUyMHNlbnRlbmNlLXRyYW5zZm9ybWVycyUyRmNsaXAtVmlULUItMzIlMjAtLXNlcXVlbmNlX2xlbmd0aCUyMDY0JTIwLS10ZXh0X2JhdGNoX3NpemUlMjAzJTIwLS1pbWFnZV9iYXRjaF9zaXplJTIwMSUyMC0tbnVtX2NoYW5uZWxzJTIwMyUyMC0taGVpZ2h0JTIwMjI0JTIwLS13aWR0aCUyMDIyNCUyMC0tdGFzayUyMGZlYXR1cmUtZXh0cmFjdGlvbiUyMC0tc3ViZm9sZGVyJTIwMF9DTElQTW9kZWwlMjBjbGlwX2VtYl9uZXVyb24lMkY=",highlighted:'optimum-cli <span class="hljs-built_in">export</span> neuron -m sentence-transformers/clip-ViT-B-32 --sequence_length 64 --text_batch_size 3 --image_batch_size 1 --num_channels 3 --height 224 --width 224 --task feature-extraction --subfolder 0_CLIPModel clip_emb_neuron/',wrap:!1}}),Z=new D({props:{title:"Option 2: Python API",local:"option-2-python-api",headingTag:"h3"}}),g=new L({props:{code:"ZnJvbSUyMG9wdGltdW0ubmV1cm9uJTIwaW1wb3J0JTIwTmV1cm9uU2VudGVuY2VUcmFuc2Zvcm1lcnMlMEElMEElMjMlMjBjb25maWdzJTIwZm9yJTIwY29tcGlsaW5nJTIwbW9kZWwlMEFpbnB1dF9zaGFwZXMlMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjJiYXRjaF9zaXplJTIyJTNBJTIwMSUyQyUwQSUyMCUyMCUyMCUyMCUyMnNlcXVlbmNlX2xlbmd0aCUyMiUzQSUyMDUxMiUyQyUwQSU3RCUwQWNvbXBpbGVyX2FyZ3MlMjAlM0QlMjAlN0IlMjJhdXRvX2Nhc3QlMjIlM0ElMjAlMjJtYXRtdWwlMjIlMkMlMjAlMjJhdXRvX2N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QlMEFlbWJlZGRpbmdzXzElMjAlM0QlMjBuZXVyb25fbW9kZWwuZW5jb2RlKHNlbnRlbmNlc18xJTJDJTIwbm9ybWFsaXplX2VtYmVkZGluZ3MlM0RUcnVlKSUwQWVtYmVkZGluZ3NfMiUyMCUzRCUyMG5ldXJvbl9tb2RlbC5lbmNvZGUoc2VudGVuY2VzXzIlMkMlMjBub3JtYWxpemVfZW1iZWRkaW5ncyUzRFRydWUpJTBBc2ltaWxhcml0eSUyMCUzRCUyMG5ldXJvbl9tb2RlbC5zaW1pbGFyaXR5KGVtYmVkZGluZ3NfMSUyQyUyMGVtYmVkZGluZ3NfMik=",highlighted:`<span class="hljs-keyword">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronSentenceTransformers

<span class="hljs-comment"># configs for compiling model</span>
input_shapes = {
    <span class="hljs-string">&quot;batch_size&quot;</span>: <span class="hljs-number">1</span>,
    <span class="hljs-string">&quot;sequence_length&quot;</span>: <span class="hljs-number">512</span>,
}
compiler_args = {<span class="hljs-string">&quot;auto_cast&quot;</span>: <span class="hljs-string">&quot;matmul&quot;</span>, <span class="hljs-string">&quot;auto_cast_type&quot;</span>: <span class="hljs-string">&quot;bf16&quot;</span>}

neuron_model = NeuronSentenceTransformers.from_pretrained(
    <span class="hljs-string">&quot;BAAI/bge-large-en-v1.5&quot;</span>,
    export=<span class="hljs-literal">True</span>,
    **input_shapes,
    **compiler_args,
)

<span class="hljs-comment"># Save locally</span>
neuron_model.save_pretrained(<span class="hljs-string">&quot;bge_emb_neuron/&quot;</span>)

<span class="hljs-comment"># Upload to the HuggingFace Hub</span>
neuron_model.push_to_hub(
    <span class="hljs-string">&quot;bge_emb_neuron/&quot;</span>, repository_id=<span class="hljs-string">&quot;optimum/bge-base-en-v1.5-neuronx&quot;</span>  <span class="hljs-comment"># Replace with your HF Hub repo id</span>
)

sentences_1 = [<span class="hljs-string">&quot;Life is pain au chocolat&quot;</span>, <span class="hljs-string">&quot;Life is galette des rois&quot;</span>]
sentences_2 = [<span class="hljs-string">&quot;Life is eclaire au cafe&quot;</span>, <span class="hljs-string">&quot;Life is mille feuille&quot;</span>]
embeddings_1 = neuron_model.encode(sentences_1, normalize_embeddings=<span class="hljs-literal">True</span>)
embeddings_2 = neuron_model.encode(sentences_2, normalize_embeddings=<span class="hljs-literal">True</span>)
similarity = neuron_model.similarity(embeddings_1, embeddings_2)`,wrap:!1}}),X=new L({props:{code:"ZnJvbSUyMG9wdGltdW0ubmV1cm9uJTIwaW1wb3J0JTIwTmV1cm9uU2VudGVuY2VUcmFuc2Zvcm1lcnMlMEElMEElMjMlMjBjb25maWdzJTIwZm9yJTIwY29tcGlsaW5nJTIwbW9kZWwlMEFpbnB1dF9zaGFwZXMlMjAlM0QlMjAlN0IlMEElMjAlMjAlMjAlMjAlMjJudW1fY2hhbm5lbHMlMjIlM0ElMjAzJTJDJTBBJTIwJTIwJTIwJTIwJTIyaGVpZ2h0JTIyJTNBJTIwMjI0JTJDJTBBJTIwJTIwJTIwJTIwJTIyd2lkdGglMjIlM0ElMjAyMjQlMkMlMEElMjAlMjAlMjAlMjAlMjJ0ZXh0X2JhdGNoX3NpemUlMjIlM0ElMjAzJTJDJTBBJTIwJTIwJTIwJTIwJTIyaW1hZ2VfYmF0Y2hfc2l6ZSUyMiUzQSUyMDElMkMlMEElMjAlMjAlMjAlMjAlMjJzZXF1ZW5jZV9sZW5ndGglMjIlM0ElMjA2NCUyQyUwQSU3RCUwQWNvbXBpbGVyX2FyZ3MlMjAlM0QlMjAlN0IlMjJhdXRvX2Nhc3QlMjIlM0ElMjAlMjJtYXRtdWwlMjIlMkMlMjAlMjJhdXRvX2Nhc3RfdHlwZSUyMiUzQSUyMCUyMmJmMTYlMjIlN0QlMEElMEFuZXVyb25fbW9kZWwlMjAlM0QlMjBOZXVyb25TZW50ZW5jZVRyYW5zZm9ybWVycy5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc2VudGVuY2UtdHJhbnNmb3JtZXJzJTJGY2xpcC1WaVQtQi0zMiUyMiUyQyUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMjBfQ0xJUE1vZGVsJTIyJTJDJTBBJTIwJTIwJTIwJTIwZXhwb3J0JTNEVHJ1ZSUyQyUwQSUyMCUyMCUyMCUyMGR5bmFtaWNfYmF0Y2hfc2l6ZSUzREZhbHNlJTJDJTBBJTIwJTIwJTIwJTIwKippbnB1dF9zaGFwZXMlMkMlMEElMjAlMjAlMjAlMjAqKmNvbXBpbGVyX2FyZ3MlMkMlMEEpJTBBJTBBJTIzJTIwU2F2ZSUyMGxvY2FsbHklMEFuZXVyb25fbW9kZWwuc2F2ZV9wcmV0cmFpbmVkKCUyMmNsaXBfZW1iX25ldXJvbiUyRiUyMiklMEElMEElMjMlMjBVcGxvYWQlMjB0byUyMHRoZSUyMEh1Z2dpbmdGYWNlJTIwSHViJTBBbmV1cm9uX21vZGVsLnB1c2hfdG9faHViKCUwQSUyMCUyMCUyMCUyMCUyMmNsaXBfZW1iX25ldXJvbiUyRiUyMiUyQyUyMHJlcG9zaXRvcnlfaWQlM0QlMjJvcHRpbXVtJTJGY2xpcF92aXRfZW1iX25ldXJvbnglMjIlMjAlMjAlMjMlMjBSZXBsYWNlJTIwd2l0aCUyMHlvdXIlMjBIRiUyMEh1YiUyMHJlcG8lMjBpZCUwQSk=",highlighted:`<span class="hljs-keyword">from</span> optimum.neuron <span class="hljs-keyword">import</span> NeuronSentenceTransformers

<span class="hljs-comment"># configs for compiling model</span>
input_shapes = {
    <span class="hljs-string">&quot;num_channels&quot;</span>: <span class="hljs-number">3</span>,
    <span class="hljs-string">&quot;height&quot;</span>: <span class="hljs-number">224</span>,
    <span class="hljs-string">&quot;width&quot;</span>: <span class="hljs-number">224</span>,
    <span class="hljs-string">&quot;text_batch_size&quot;</span>: <span class="hljs-number">3</span>,
    <span class="hljs-string">&quot;image_batch_size&quot;</span>: <span class="hljs-number">1</span>,
    <span class="hljs-string">&quot;sequence_length&quot;</span>: <span class="hljs-number">64</span>,
}
compiler_args = {<span class="hljs-string">&quot;auto_cast&quot;</span>: <span class="hljs-string">&quot;matmul&quot;</span>, <span class="hljs-string">&quot;auto_cast_type&quot;</span>: <span class="hljs-string">&quot;bf16&quot;</span>}

neuron_model = NeuronSentenceTransformers.from_pretrained(
    <span class="hljs-string">&quot;sentence-transformers/clip-ViT-B-32&quot;</span>,
    subfolder=<span class="hljs-string">&quot;0_CLIPModel&quot;</span>,
    export=<span class="hljs-literal">True</span>,
    dynamic_batch_size=<span class="hljs-literal">False</span>,
    **input_shapes,
    **compiler_args,
)

<span class="hljs-comment"># Save locally</span>
neuron_model.save_pretrained(<span class="hljs-string">&quot;clip_emb_neuron/&quot;</span>)

<span class="hljs-comment"># Upload to the HuggingFace Hub</span>
neuron_model.push_to_hub(
    <span class="hljs-string">&quot;clip_emb_neuron/&quot;</span>, repository_id=<span class="hljs-string">&quot;optimum/clip_vit_emb_neuronx&quot;</span>  <span class="hljs-comment"># Replace with your HF Hub repo id</span>
)`,wrap:!1}}),{c(){M=c("meta"),G=n(),W=c("p"),S=n(),i(j.$$.fragment),C=n(),i(J.$$.fragment),$=n(),U=c("p"),U.innerHTML=K,E=n(),i(b.$$.fragment),N=n(),i(h.$$.fragment),q=n(),T=c("ul"),T.innerHTML=O,v=n(),i(d.$$.fragment),R=n(),f=c("ul"),f.innerHTML=ll,z=n(),i(w.$$.fragment),A=n(),i(Z.$$.fragment),Q=n(),I=c("ul"),I.innerHTML=sl,k=n(),i(g.$$.fragment),x=n(),_=c("ul"),_.innerHTML=el,F=n(),i(X.$$.fragment),H=n(),V=c("p"),this.h()},l(l){const s=ol("svelte-u9bgzb",document.head);M=y(s,"META",{name:!0,content:!0}),s.forEach(e),G=a(l),W=y(l,"P",{}),tl(W).forEach(e),S=a(l),m(j.$$.fragment,l),C=a(l),m(J.$$.fragment,l),$=a(l),U=y(l,"P",{"data-svelte-h":!0}),B(U)!=="svelte-18qnw3c"&&(U.innerHTML=K),E=a(l),m(b.$$.fragment,l),N=a(l),m(h.$$.fragment,l),q=a(l),T=y(l,"UL",{"data-svelte-h":!0}),B(T)!=="svelte-1yh68uj"&&(T.innerHTML=O),v=a(l),m(d.$$.fragment,l),R=a(l),f=y(l,"UL",{"data-svelte-h":!0}),B(f)!=="svelte-18kij33"&&(f.innerHTML=ll),z=a(l),m(w.$$.fragment,l),A=a(l),m(Z.$$.fragment,l),Q=a(l),I=y(l,"UL",{"data-svelte-h":!0}),B(I)!=="svelte-1yh68uj"&&(I.innerHTML=sl),k=a(l),m(g.$$.fragment,l),x=a(l),_=y(l,"UL",{"data-svelte-h":!0}),B(_)!=="svelte-18kij33"&&(_.innerHTML=el),F=a(l),m(X.$$.fragment,l),H=a(l),V=y(l,"P",{}),tl(V).forEach(e),this.h()},h(){nl(M,"name","hf:doc:metadata"),nl(M,"content",yl)},m(l,s){rl(document.head,M),t(l,G,s),t(l,W,s),t(l,S,s),p(j,l,s),t(l,C,s),p(J,l,s),t(l,$,s),t(l,U,s),t(l,E,s),p(b,l,s),t(l,N,s),p(h,l,s),t(l,q,s),t(l,T,s),t(l,v,s),p(d,l,s),t(l,R,s),t(l,f,s),t(l,z,s),p(w,l,s),t(l,A,s),p(Z,l,s),t(l,Q,s),t(l,I,s),t(l,k,s),p(g,l,s),t(l,x,s),t(l,_,s),t(l,F,s),p(X,l,s),t(l,H,s),t(l,V,s),Y=!0},p:Ml,i(l){Y||(o(j.$$.fragment,l),o(J.$$.fragment,l),o(b.$$.fragment,l),o(h.$$.fragment,l),o(d.$$.fragment,l),o(w.$$.fragment,l),o(Z.$$.fragment,l),o(g.$$.fragment,l),o(X.$$.fragment,l),Y=!0)},o(l){r(j.$$.fragment,l),r(J.$$.fragment,l),r(b.$$.fragment,l),r(h.$$.fragment,l),r(d.$$.fragment,l),r(w.$$.fragment,l),r(Z.$$.fragment,l),r(g.$$.fragment,l),r(X.$$.fragment,l),Y=!1},d(l){l&&(e(G),e(W),e(S),e(C),e($),e(U),e(E),e(N),e(q),e(T),e(v),e(R),e(f),e(z),e(A),e(Q),e(I),e(k),e(x),e(_),e(F),e(H),e(V)),e(M),u(j,l),u(J,l),u(b,l),u(h,l),u(d,l),u(w,l),u(Z,l),u(g,l),u(X,l)}}}const yl='{"title":"Sentence Transformers 🤗","local":"sentence-transformers-","sections":[{"title":"Export to Neuron","local":"export-to-neuron","sections":[{"title":"Option 1: CLI","local":"option-1-cli","sections":[],"depth":3},{"title":"Option 2: Python API","local":"option-2-python-api","sections":[],"depth":3}],"depth":2}],"depth":1}';function jl(P){return il(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class dl extends ml{constructor(M){super(),pl(this,M,jl,cl,al,{})}}export{dl as component};
