ajeetsraina commited on
Commit
26faa32
·
1 Parent(s): 2bdbc80
Files changed (2) hide show
  1. Dockerfile +14 -0
  2. inference.py +28 -0
Dockerfile ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Specify a base image that contains the necessary dependencies for running Hugging Face LLMs.
2
+ FROM python:3.9-transformers
3
+
4
+ # Copy your Hugging Face LLM files into the container.
5
+ COPY . /app
6
+
7
+ # Set the working directory to the directory where your Hugging Face LLM files are located.
8
+ WORKDIR /app
9
+
10
+ # Expose port 8000 for your Hugging Face LLM.
11
+ EXPOSE 8000
12
+
13
+ # Start the Hugging Face LLM server.
14
+ CMD ["python", "inference.py"]
inference.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import transformers
2
+
3
+ class LLMInferenceServer:
4
+ def __init__(self, model_name):
5
+ self.model = transformers.AutoModelForCausalLM.from_pretrained(model_name)
6
+
7
+ def generate(self, prompt, max_length=100):
8
+ inputs = transformers.InputFeatures(input_ids=[self.model.config.bos_token_id], attention_mask=[1])
9
+ output = self.model.generate(inputs, max_length=max_length, prompt=prompt)
10
+ return output[0]
11
+
12
+ if __name__ == '__main__':
13
+ model_name = "google/bigbird-roberta-base"
14
+ server = LLMInferenceServer(model_name)
15
+
16
+ from flask import Flask, request, jsonify
17
+
18
+ app = Flask(__name__)
19
+
20
+ @app.route("/generate", methods=["POST"])
21
+ def generate():
22
+ prompt = request.json["prompt"]
23
+ max_length = request.json["max_length"]
24
+
25
+ response = server.generate(prompt, max_length)
26
+ return jsonify({"response": response})
27
+
28
+ app.run(host="0.0.0.0", port=8000)