Spaces:
Build error
Build error
Update Dockerfile
Browse files6 unmodified lines789101112138 unmodified lines222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676 unmodified linesPYTHONUNBUFFERED=1 \PYTHONOPTIMIZE=2 \TOKENIZERS_PARALLELISM=false \HF_HUB_ENABLE_HF_TRANSFER=1 \OMP_NUM_THREADS=1 \MKL_NUM_THREADS=1 \NUMEXPR_NUM_THREADS=1 \8 unmodified linesWORKDIR /appRUN mkdir -p /cache && chmod -R 777 /cache# write app.py inlineRUN printf 'import os, torch, numpy as np\n\from fastapi import FastAPI\n\from fastapi.responses import ORJSONResponse\n\from pydantic import BaseModel\n\from typing import List\n\from sentence_transformers import SentenceTransformer\n\\n\try:\n\torch.set_num_threads(int(os.getenv("INTRA_THREADS","1")))\n\torch.set_num_interop_threads(1)\n\except Exception:\n\pass\n\\n\app = FastAPI(title=\"gte-large-embed\", default_response_class=ORJSONResponse)\n\device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n\model_path = \"/cache/preload\" if os.path.isdir(\"/cache/preload\") else \"thenlper/gte-large\"\n\model = SentenceTransformer(model_path, device=device)\n\\n\class EmbedIn(BaseModel):\n\texts: List[str]\n\normalize: bool = True\n\batch_size: int = 128\n\\n\@app.on_event(\"startup\")\n\def warmup():\n\with torch.inference_mode():\n\_ = model.encode([\"warmup\",\"ready\"], normalize_embeddings=True, batch_size=2, convert_to_numpy=True, show_progress_bar=False)\n\\n\@app.get(\"/health\")\n\def health():\n\return {\"ok\": True, \"device\": device, \"threads\": {\"intra\": torch.get_num_threads()}}\n\\n\@app.post(\"/embed\")\n\def embed(inp: EmbedIn):\n\with torch.inference_mode():\n\vecs = model.encode(inp.texts, normalize_embeddings=inp.normalize, batch_size=inp.batch_size, convert_to_numpy=True, show_progress_bar=False)\n\return {\"embeddings\": vecs.tolist(), \"dim\": int(vecs.shape[1]), \"n\": int(vecs.shape[0])}\n' > /app/app.py# preload model into /cache (no heredoc, one-liner)RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('thenlper/gte-large').save('/cache/preload')"EXPOSE 78606 unmodified lines7891011128 unmodified lines21222324252627286 unmodified linesPYTHONUNBUFFERED=1 \PYTHONOPTIMIZE=2 \TOKENIZERS_PARALLELISM=false \OMP_NUM_THREADS=1 \MKL_NUM_THREADS=1 \NUMEXPR_NUM_THREADS=1 \8 unmodified linesWORKDIR /appRUN mkdir -p /cache && chmod -R 777 /cacheRUN printf 'import os, torch, numpy as np\nfrom fastapi import FastAPI\nfrom fastapi.responses import ORJSONResponse\nfrom pydantic import BaseModel\nfrom typing import List\nfrom sentence_transformers import SentenceTransformer\n\ntry:\n torch.set_num_threads(int(os.getenv("INTRA_THREADS","1")))\n torch.set_num_interop_threads(1)\nexcept Exception:\n pass\n\napp = FastAPI(title="gte-large-embed", default_response_class=ORJSONResponse)\ndevice = "cuda" if torch.cuda.is_available() else "cpu"\nmodel_path = "/cache/preload" if os.path.isdir("/cache/preload") else "thenlper/gte-large"\nmodel = SentenceTransformer(model_path, device=device)\n\nclass EmbedIn(BaseModel):\n texts: List[str]\n normalize: bool = True\n batch_size: int = 128\n\n@app.on_event("startup")\ndef warmup():\n with torch.inference_mode():\n _ = model.encode(["warmup","ready"], normalize_embeddings=True, batch_size=2, convert_to_numpy=True, show_progress_bar=False)\n\n@app.get("/health")\ndef health():\n return {"ok": True, "device": device, "threads": {"intra": torch.get_num_threads()}}\n\n@app.post("/embed")\ndef embed(inp: EmbedIn):\n with torch.inference_mode():\n vecs = model.encode(inp.texts, normalize_embeddings=inp.normalize, batch_size=inp.batch_size, convert_to_numpy=True, show_progress_bar=False)\n return {"embeddings": vecs.tolist(), "dim": int(vecs.shape[1]), "n": int(vecs.shape[0])}\n' > /app/app.pyRUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('thenlper/gte-large').save('/cache/preload')"EXPOSE 7860
Dockerfile+1-40