Run this model with HF Jobs
Run unity/inference-engine-phi-1_5 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/unity/inference-engine-phi-1_5. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/unity/inference-engine-phi-1_5 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Evaluate on a benchmark
Use HF Jobs to evaluate https://huggingface.co/unity/inference-engine-phi-1_5. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
Quantize for lower memory use
Use HF Jobs to create a 4-bit version of https://huggingface.co/unity/inference-engine-phi-1_5. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
Instructions to use unity/inference-engine-phi-1_5 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- unity-sentis
How to use unity/inference-engine-phi-1_5 with unity-sentis:
string modelName = "[Your model name here].sentis"; Model model = ModelLoader.Load(Application.streamingAssetsPath + "/" + modelName); IWorker engine = WorkerFactory.CreateWorker(BackendType.GPUCompute, model); // Please see provided C# file for more details
- Notebooks
- Google Colab
- Kaggle
Upload RunPhi15.cs
Browse files2 unmodified lines345678910111213141516171819203 unmodified lines242526272829303132333435363738394041424344454647484910 unmodified lines606162636465662 unmodified lines69707172737475767778798081828384858687888990919 unmodified lines10110210310410510610710810911011111211311411511611711815 unmodified lines1341351361371381397 unmodified lines1471481491501511521531541551561 unmodified line15815916016116216316416516616716816917017117217317417517617717817918034 unmodified lines2152162172182192202211 unmodified line22322422522622722822923023144 unmodified lines2762772782792802812822 unmodified linesusing UnityEngine;using Unity.Sentis;using System.IO;using Newtonsoft.Json;using System.Text;/** Phi 1.5 Inference Code* =======================** Put this script on the Main Camera** In Assets/StreamingAssets put:** phi15.sentis* vocab.json* merges.txt*3 unmodified lines*/public class RunPhi15 : MonoBehaviour{const BackendType backend = BackendType.GPUCompute;//string outputString = "Question: \"What is the capital of France?\"\n Correct answer: \"";//string outputString = "The human asked, \"What is your favourite animal?\" so the wise man answered correctly, \"";string outputString = "Once upon a time, there were three";//string outputString = "// Javascript function for prime numbers";// This is how many tokens you want. It can be adjusted.const int maxTokens = 100;//Make this smaller for more randomnessconst float predictability = 5;//Special tokensconst int END_OF_TEXT = 50256;Ops ops;ITensorAllocator allocator;//Store the vocabularystring[] tokens;10 unmodified lines//stop after this many tokensconst int stopAfter = 200;int totalTokens = 0;2 unmodified linesvoid Start(){allocator = new TensorCachingAllocator();ops = WorkerFactory.CreateOps(backend, allocator);SetupWhiteSpaceShifts();LoadVocabulary();Model model = ModelLoader.Load(Application.streamingAssetsPath + "/phi15.sentis");engine = WorkerFactory.CreateWorker(backend, model);GO(outputString);}public void GO(string text){outputString = text;DecodePrompt(outputString);runInference = true;}9 unmodified linesvoid RunInference(){using var tokensSoFar = new TensorInt(new TensorShape(1, maxTokens), outputTokens);engine.Execute(tokensSoFar);var tokensOut = engine.PeekOutput() as TensorFloat;using var row = ops.Slice(tokensOut, new[] { currentToken }, new[] { currentToken + 1 }, new[] { 1 }, new[] { 1 });using var rowB = ops.Mul(predictability, row);using var probs = ops.Softmax(rowB, 2);probs.MakeReadable();int ID = SelectRandomToken(probs.ToReadOnlyArray());if (currentToken >= maxTokens - 1){for (int i = 0; i < maxTokens - 1; i++) outputTokens[i] = outputTokens[i + 1];15 unmodified lineselse outputString += GetUnicodeText(tokens[ID]);Debug.Log(outputString);}void DecodePrompt(string text)7 unmodified linescurrentToken = inputTokens.Count - 1;}void LoadVocabulary(){var jsonText = File.ReadAllText(Application.streamingAssetsPath + "/vocab.json");vocab = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, int>>(jsonText);tokens = new string[vocab.Count];foreach (var item in vocab)1 unmodified linetokens[item.Value] = item.Key;}merges = File.ReadAllLines(Application.streamingAssetsPath + "/merges.txt");}int SelectRandomToken(float[] probs){float p = UnityEngine.Random.Range(0, 1f);float t = 0;for (int i = 0; i < probs.Length; i++){t += probs[i];if (p < t){return i;}}return probs.Length - 1;}// Translates encoded special characters to Unicode34 unmodified linesfor (int i = 0, n = 0; i < 256; i++){encodedCharacters[i] = i;if (IsWhiteSpace((char)i)){encodedCharacters[i] = n + 256;whiteSpaceCharacters[n++] = i;1 unmodified line}}bool IsWhiteSpace(char c){return !(('!' <= c && c <= '~') || ('�' <= c && c <= '�') || ('�' <= c && c <= '�'));}List<int> GetTokens(string text)44 unmodified linesprivate void OnDestroy(){engine?.Dispose();ops?.Dispose();allocator?.Dispose();}}2 unmodified lines345678910111213141516171819203 unmodified lines24252627282930313233343536373839404142434445464710 unmodified lines585960616263642 unmodified lines676869707172737475767778798081828384858687888990919293949 unmodified lines10410510610710810911011111211311411511611711811912012115 unmodified lines1371381391401411421437 unmodified lines1511521531541551561571581591 unmodified line16116216316416516616734 unmodified lines2022032042052062072081 unmodified line21021121221321421521621721821944 unmodified lines2642652662672682692 unmodified linesusing UnityEngine;using Unity.Sentis;using System.IO;using System.Text;using FF = Unity.Sentis.Functional;/** Phi1.5 Inference Code* ===========================** Put this script on the Main Camera** In Assets/StreamingAssets put:** phi15.sentis (or put in asset folder)* vocab.json* merges.txt*3 unmodified lines*/public class RunPhi15: MonoBehaviour{//Drop the tinystories.sentis or onnx file on here if using an asset://public ModelAsset asset;const BackendType backend = BackendType.GPUCompute;//string outputString = "Once upon a time, there were three bears";string outputString = "One day an alien came down from Mars. It saw a chicken";// This is how many tokens you want. It can be adjusted.const int maxTokens = 100;//Make this smaller for more randomnessconst float predictability = 5f;//Special tokensconst int END_OF_TEXT = 50256;//Store the vocabularystring[] tokens;10 unmodified lines//stop after this many tokensconst int stopAfter = 100;int totalTokens = 0;2 unmodified linesvoid Start(){SetupWhiteSpaceShifts();LoadVocabulary();var model1 = ModelLoader.Load(Path.Join(Application.streamingAssetsPath , "phi15.sentis"));int outputIndex = model1.outputs.Count - 1;//var model1 = ModelLoader.Load(asset);//Create a new model to select the random token:var model2 = FF.Compile((input, currentToken) =>{var row = FF.Select(model1.Forward(input)[outputIndex], 1, currentToken);return FF.Multinomial(predictability * row, 1);},(model1.inputs[0], InputDef.Int(new TensorShape())));engine = WorkerFactory.CreateWorker(backend, model2);DecodePrompt(outputString);runInference = true;}9 unmodified linesvoid RunInference(){using var tokensSoFar = new TensorInt(new TensorShape(1, maxTokens), outputTokens);using var index = new TensorInt(currentToken);engine.Execute(new Dictionary<string, Tensor> { {"input_0", tokensSoFar }, { "input_1", index }});var probs = engine.PeekOutput() as TensorInt;//Debug.Log(probs.shape);probs.CompleteOperationsAndDownload();int ID = probs[0];//shift window down if got to the endif (currentToken >= maxTokens - 1){for (int i = 0; i < maxTokens - 1; i++) outputTokens[i] = outputTokens[i + 1];15 unmodified lineselse outputString += GetUnicodeText(tokens[ID]);Debug.Log(outputString);}void DecodePrompt(string text)7 unmodified linescurrentToken = inputTokens.Count - 1;}void LoadVocabulary(){var jsonText = File.ReadAllText(Path.Join(Application.streamingAssetsPath , "vocab.json"));vocab = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, int>>(jsonText);tokens = new string[vocab.Count];foreach (var item in vocab)1 unmodified linetokens[item.Value] = item.Key;}merges = File.ReadAllLines(Path.Join(Application.streamingAssetsPath , "merges.txt"));}// Translates encoded special characters to Unicode34 unmodified linesfor (int i = 0, n = 0; i < 256; i++){encodedCharacters[i] = i;if (IsWhiteSpace(i)){encodedCharacters[i] = n + 256;whiteSpaceCharacters[n++] = i;1 unmodified line}}bool IsWhiteSpace(int i){//returns true if it is a whitespace characterreturn i <= 32 || (i >= 127 && i <= 160) || i == 173;}List<int> GetTokens(string text)44 unmodified linesprivate void OnDestroy(){engine?.Dispose();}}
RunPhi15.cs+43-56