Get Started with Token Factory - Storage Namespace - Rafay Product Documentation

Advanced

In this guide you will set up a storage namespace for hosting a GenAI model that is pulled from Hugging Face. Storage namespaces allow models to be loaded efficiently into GPU memory and avoid repeated downloads from remote repositories.


Assumptions

This exercise assumes you have completed the Token Factory Basics Get Started Guide and you have access to an Amazon S3 bucket for hosting models.


1. Create Storage Namespace

In this section, you will create the storage namespace.


2. Create Storage Namespace Access Keys

In this section, you will create an access key that will be used to load content into the storage namespace.


3. Create Model

In this section, you will create a model. A model represents the LLM that the administrator onboarding into the system. Each model includes core metadata such as name, description, provider, and use case. This information determines how the model is organized, how it appears in the console, and how it will later be deployed for inference.


LLM Use Case

Info: For the model to support chat protocol, vLLM requires the model to include a chat template in its tokenizer configuration. The chat template is a Jinja2 template that specifies how roles, messages, and other chat-specific tokens are encoded in the input.


Model Selection and Location

In this guide, the deployments will download the model weights during deployment from the Storage Namespace.

Important: A newly created model has zero deployments by default. One or more deployments can be created for the same model, each with different endpoints or runtime configurations.


4. Model Sharing

Next, you will share the model with a downstream Tenant Organization to be used by end users.


5. Upload Model Content

In this section, you will download a model from Hugging Face and upload the model content into the storage namespace.

Install AWS CLI

The AWS CLI is used to sync model content to the storage namespace.

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Configure AWS Credentials

Use the Access Key generated on the portal to authenticate the AWS CLI.

aws configure

Provide the following:

Important: When configuring the AWS CLI, be sure to enter the Access Keys generated from the Ops Portal and not your AWS access keys.

Download Model

Next, you will use the Hugging Face CLI to download a model locally.

Important: Instructions for installing the Hugging Face CLI can be found at https://huggingface.co/docs/huggingface_hub/guides/cli

hf auth login
hf download Qwen/Qwen2-0.5B-Instruct
Fetching 10 files: 100%|█████████████████████████████████████| 10/10 [00:02<00:00,  3.87it/s]
Download complete: : 1.00GB [00:02, 656MB/s]              /root/.cache/huggingface/hub/models--Qwen--Qwen2-0.5B-Instruct/snapshots/c540970f9e29518b1d8f06ab8b24cba66ad77b6d0,  3.35it/s]
Download complete: : 1.00GB [00:02, 384MB/s]

Upload Model

Next, you will upload the model to the storage namespace.

This command uploads all files from the current directory to the model’s storage location using the Rafay gateway and the selected Storage Namespace.

After the upload completes successfully, the model content is available in the bucket and the model becomes ready for deployment.


6. Create Model Deployment

In this section, you will create a model deployment. Model Deployments define how a LLM is deployed for inference. A deployment binds a model to an endpoint, selects an inference engine, and configures runtime resources such as replicas, CPU, memory, and GPU.


Engine Selection

Note: Operators can select the version of vLLM they wish to use. The vLLM image can be pretty large in size (Gigabytes) and operators may wish to host the image in a local container registry to ensure fast/reliable deployments.


Resources

Specify the CPU, memory, GPU and storage resources that you wish to allocate to vLLM.


Metering

In this section, the operator will specify how usage will be metered. They will specify the currency and the rate for every million tokens. The Rafay Token Factory counts input and output tokens separately.

After a few minutes, the model will be deployed to the specified cluster.


7. Model Deployment Sharing

Next, you will share the model with a downstream Tenant Organization to be used by end users.


8. End User Utilization

Finally, you will use a tenant end user account and utilize the inference endpoint. In this guide, we will execute the commands directly from the Kubernetes cluster.

export API_KEY=<API KEY VALUE>
{
   "id":"chatcmpl-1c0e2496-0ed0-40ba-9832-c0c2df775f2d",
   "object":"chat.completion",
   "created":1773340699,
   "model":"gs-storage-ns-deployment",
   "choices":[
      {
         "index":0,
         "message":{
            "role":"assistant",
            "content":"There isn't necessarily one \"best\" open-source inference library as what works well for one application may not work so well for another. However, there are several popular and highly regarded libraries that you might consider depending on your specific use case:\n\n1. TensorFlow: A powerful framework developed by Google, widely used for both research and production purposes.\n\n2. PyTorch: Developed by Facebook AI Research (FAIR), it's known for its flexibility and ease of use.\n\n3. ONNX Runtime: This is an open-source runtime for running models produced with the Open Neural Network Exchange (ONNX).\n\n4. Caffe: An old but robust deep learning framework that has seen updates since its original development.\n\n5. MXNet: Another Python-based library designed to be flexible and scalable.\n\n6. TorchScript: Part of the Torch project from the University of Sydney, this allows models written in Torch to run efficiently on CPUs and GPUs.\n\n7. CoreML: Apple’s own machine learning model format, which can be converted to many frameworks including TensorFlow and PyTorch.\n\n8. ML.js: A JavaScript library for building and deploying neural networks.\n\n9. Keras: A high-level neural networks API built on top of Theano or Tensorflow, which is also very popular.\n\n",
            "refusal":null,
            "annotations":null,
            "audio":null,
            "function_call":null,
            "tool_calls":[

],
            "reasoning":null,
            "reasoning_content":null
         },
         "logprobs":null,
         "finish_reason":"length",
         "stop_reason":null,
         "token_ids":null
      }
   ],
   "service_tier":null,
   "system_fingerprint":null,
   "usage":{
      "prompt_tokens":30,
      "total_tokens":286,
      "completion_tokens":256,
      "prompt_tokens_details":null
   },
   "prompt_logprobs":null,
   "prompt_token_ids":null,
   "kv_transfer_params":null
}