{"id":22547773,"url":"https://github.com/LittleLittleCloud/Torchsharp-phi","last_synced_at":"2025-08-04T08:33:24.788Z","repository":{"id":219557360,"uuid":"749281112","full_name":"LittleLittleCloud/Torchsharp-phi","owner":"LittleLittleCloud","description":"Torchsharp port of phi-series model","archived":true,"fork":false,"pushed_at":"2024-08-22T22:21:53.000Z","size":174,"stargazers_count":9,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-08-23T00:01:58.584Z","etag":null,"topics":["ai","llm","phi","slm","torchsharp"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LittleLittleCloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-28T05:08:37.000Z","updated_at":"2024-08-22T22:22:03.000Z","dependencies_parsed_at":"2024-05-02T19:55:39.471Z","dependency_job_id":"b90ccddc-7ded-414f-8365-2cb9162e5079","html_url":"https://github.com/LittleLittleCloud/Torchsharp-phi","commit_stats":null,"previous_names":["littlelittlecloud/torchsharp-phi"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LittleLittleCloud%2FTorchsharp-phi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LittleLittleCloud%2FTorchsharp-phi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LittleLittleCloud%2FTorchsharp-phi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LittleLittleCloud%2FTorchsharp-phi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LittleLittleCloud","download_url":"https://codeload.github.com/LittleLittleCloud/Torchsharp-phi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228617282,"owners_count":17946637,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","llm","phi","slm","torchsharp"],"created_at":"2024-12-07T15:12:53.776Z","updated_at":"2024-12-07T15:12:56.169Z","avatar_url":"https://github.com/LittleLittleCloud.png","language":"C#","funding_links":[],"categories":["Working with Local Models"],"sub_categories":[],"readme":"# Archived\nThe implementation of this repo has been ported to [`Microsoft.ML.GenAI.Phi`](https://github.com/dotnet/machinelearning/tree/main/src/Microsoft.ML.GenAI.Phi)\n\n## Torchsharp Phi\n\nThis repo contains a torchsharp implementation for phi model.\n\n## Quick Start (Use Phi-2 model as an example)\nTo run the Phi model on your local machine, the following prerequisites are required:\n- dotnet 6 or above\n- git lfs, this is to download the model file from hugging face\n\n### Step 1: Get the model weight from huggingface\nTo get Phi-2 model weight, run the following command to download model weight from huggingface. Be sure to have git lfs installed.\n```bash\ngit clone https://huggingface.co/microsoft/phi-2\n```\n\u003e [!Note]\n\u003e To run Phi-2 model on GPU, it's recommended to use a machine with at least 8GB of GPU memory.\n\n\u003e [!Note]\n\u003e Loading other Phi model should be similar but I haven't test them yet. Please create an issue if you have trouble loading other Phi models.\n\n### Step 2: Run the model\nClone this repo and replace the `phi2Folder` folder with where you download huggingface model weight in [Program.cs](./Program.cs#L13)\n\nThen run the following command to start the model:\n```bash\ndotnet run\n```\n\n## Intended Uses\n\n### Chat Format\n```csharp\nvar chatPrompt = @\"Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?\nBob: Well, have you tried creating a study schedule and sticking to it?\nAlice: Yes, I have, but it doesn't seem to help much.\nBob: Hmm, maybe you should try studying in a quiet environment, like the library.\nAlice:\";\nvar chatOutput = phi2.Generate(tokenizer, chatPrompt, maxLen: 256, temperature: 0.3f, stopSequences: [ \"Bob:\"]);\nConsole.WriteLine(chatOutput);\n```\n#### Output (include original prompt)\n```\nAlice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?\nBob: Well, have you tried creating a study schedule and sticking to it?\nAlice: Yes, I have, but it doesn't seem to help much.\nBob: Hmm, maybe you should try studying in a quiet environment, like the library.\nAlice: That's a good idea. I'll give it a try. Thanks, Bob!\n```\n\n### QA Format\n```csharp\nvar prompt = @\"Instruction: A skier slides down a frictionless slope of height 40m and length 80m, what's the skier's speed at the bottom?\nOutput:\";\nvar output = phi2.Generate(tokenizer, prompt, maxLen: 256, temperature: 0.1f);\nConsole.WriteLine(output);\n```\n\n#### Output (include original prompt)\n```\nInstruction: A skier slides down a frictionless slope of height 40m and length 80m, what's the skier's speed at the bottom?!\nOutput: The skier's speed at the bottom of the slope can be calculated using the conservation of mechanical energy. At the top of the slope, the skier has gravitational potential energy (PE) and no kinetic energy (KE). At the bottom of the slope, the skier has only kinetic energy (KE) and no potential energy (PE). Therefore, the initial potential energy is equal to the final kinetic energy:\n\nPE(top) = KE(bottom)\nmgh = (1/2)mv^2\n\nwhere m is the mass of the skier, g is the acceleration due to gravity, h is the height of the slope, and v is the speed of the skier at the bottom.\n\nSolving for v, we get:\n\nv = sqrt(2gh)\n\nPlugging in the given values, we get:\n\nv = sqrt(2 * 9.8 * 40)\nv = 28.28 m/s\n\nSo, the skier's speed at the bottom of the slope is 28.28 m/s\n```\n\n### Code Format\n```csharp\nvar codePrompt = @\"Complete the following code\n```python\ndef print_prime(n):\n    # print all prime numbers less than n\";\nvar codeOutput = phi2.Generate(tokenizer, codePrompt, maxLen: 256, temperature: 0f, stopSequences: [ \"```\"]);\nConsole.WriteLine(codeOutput);\n```\n\n#### Output (include original prompt)\n```\nComplete the following code\n```python\ndef print_prime(n):\n    # print all prime numbers less than n\n    for i in range(2, n):\n        for j in range(2, i):\n            if i % j == 0:\n                break\n        else:\n            print(i)\n\nprint_prime(10)\n```\n\n### See also\n- [Torchsharp-llama](https://github.com/LittleLittleCloud/Torchsharp-llama): A torchsharp implementation for llama 2 model\n\n## Further reading: What's Phi?\nPhi model is a suite of small language models developed by Microsoft Research. Until January 2024, there are three models available as follows:\n- [Phi-2](https://huggingface.co/microsoft/phi-2), A 2.7B parameter model trained using the same data source with Phi-1.5 and augmented with a new data source that consists of various NLP synthetic texts and filtered websites (for safety and educational value).\n- [Phi-1.5](https://huggingface.co/microsoft/phi-1_5), A 1.3B parameter model which demonstrates a nearly state-of-the-art performance among models with less than 10 billion parameters.\n- [Phi-1](https://huggingface.co/microsoft/phi-1), A 1.3B parameter model, specialized for basic Python coding.\n\n\u003e [!Warning]\n\u003e All the Phi-series models does not fined tuned with RLHF, which means the model might generate offensive content. Please use with caution.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLittleLittleCloud%2FTorchsharp-phi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FLittleLittleCloud%2FTorchsharp-phi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FLittleLittleCloud%2FTorchsharp-phi/lists"}