Skip to content

Commit

Permalink
Merge pull request #31 from beclab/feat/bertv3-embedding
Browse files Browse the repository at this point in the history
feat: add r4userembedding with model image
  • Loading branch information
bleachzou3 authored Sep 23, 2024
2 parents 7b50055 + 0b21bde commit 335dad0
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/update_r4userembedding_with_model.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Publish to Dockerhub ( userembedding )

on:
workflow_dispatch:
inputs:
tags:
description: 'Release Tags'

jobs:
publish_dockerhub_amd64:
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASS }}

- name: Build r4userembeddingwithmodel and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }}-amd64
file: Dockerfile.r4userembeddingwithmodel
platforms: linux/amd64

publish_dockerhub_arm64:
runs-on: self-hosted
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASS }}

- name: Build r4userembeddingwithmodel and push Docker image
uses: docker/build-push-action@v3
with:
push: true
tags: beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }}-arm64
file: Dockerfile.r4userembeddingwithmodel
platforms: linux/arm64

publish_manifest:
needs:
- publish_dockerhub_amd64
- publish_dockerhub_arm64
runs-on: ubuntu-latest
steps:
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASS }}

- name: Push manifest
run: |
docker manifest create beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }} --amend beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }}-amd64 --amend beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }}-arm64
docker manifest push beclab/r4userembeddingwithmodel:${{ github.event.inputs.tags }}
35 changes: 35 additions & 0 deletions Dockerfile.r4userembeddingwithmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
FROM ubuntu:jammy As builder

# RUN apk add openssl-dev musl-dev g++

RUN mkdir -p /userembedding && \
apt update && \
apt install curl -y && \
curl https://sh.rustup.rs -sSf | bash -s -- -y && \
# echo 'source $HOME/.cargo/env' >> $HOME/.bashrc && \
apt install build-essential -y && \
apt-get install libssl-dev -y && \
apt-get install pkg-config -y

ENV PATH="/root/.cargo/bin:${PATH}"
WORKDIR /userembedding
COPY user-embedding/src /userembedding/src
COPY user-embedding/Cargo.toml /userembedding/Cargo.toml
RUN cargo build --release
RUN /userembedding/target/release/downloadmodel



FROM ubuntu:jammy

# Import from builder.


WORKDIR /userembedding

# Copy our build
COPY --from=builder /root/.cache/huggingface /root/.cache/huggingface
COPY --from=builder /userembedding/target/release/userembedding ./


CMD ["/userembedding/userembedding"]
4 changes: 4 additions & 0 deletions user-embedding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ tracing-subscriber = "0.3.18"
[[bin]]
name = "userembedding"
path = "src/userembedding.rs"

[[bin]]
name = "downloadmodel"
path = "src/download_model.rs"
31 changes: 31 additions & 0 deletions user-embedding/src/download_model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use hf_hub::api::sync::Api;

use userembedding::{
common,
embedding_common::{self, MODEL_RELATED_INFO_MAP},
};

fn download_models() -> Result<(), Box<dyn std::error::Error>> {
for (_, model_related_info) in MODEL_RELATED_INFO_MAP.iter() {
tracing::info!("Downloading model {}...", model_related_info.model_name);
let default_model: String = model_related_info.hugging_face_model_name.to_string();
let default_revision: String = model_related_info.hugging_face_model_revision.to_string();
let (_, _) =
embedding_common::build_model_and_tokenizer(default_model, default_revision).unwrap();
tracing::info!(
"Model {} downloaded successfully",
model_related_info.model_name
);
}

Ok(())
}

fn main() {
// Call the function to download models
common::init_logger();

if let Err(e) = download_models() {
eprintln!("Error downloading models: {}", e);
}
}

0 comments on commit 335dad0

Please sign in to comment.