// eslint-disable-next-line no-var
var flatDeep = function (arr, depth) {
forEach.call(arr, (val) => {
if (depth > 0 && Array.isArray(val)) {
flatDeep(val, depth - 1);
} else {
result.push(val);
}
});
};
flatDeep(this, depth);
return result;
},
});
}
</script><script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"post":"{\"_id\":\"6461d16093a6a31920e80c67\",\"partOfPublication\":true,\"author\":{\"_id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"photo\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"username\":\"ehartford\",\"bio\":\"\u003cp\u003eI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"socialMedia\":{\"website\":\"\",\"github\":\"https://github.com/ehartford\",\"twitter\":\"https://twitter.com/erhartford\",\"facebook\":\"\",\"stackoverflow\":\"https://stackoverflow.com/users/559378/eric-hartford\",\"linkedin\":\"https://www.linkedin.com/in/ehartford\"},\"isDeactivated\":false},\"bookmarkedIn\":[],\"publication\":{\"_id\":\"64211e867988b96a2e13d599\",\"author\":{\"_id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"photo\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"username\":\"ehartford\"},\"badgePageEnabled\":true,\"description\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"domain\":\"erichartford.com\",\"domainStatus\":{\"ready\":true,\"certIssued\":true},\"wwwPrefixedDomain\":\"www.erichartford.com\",\"wwwPrefixedDomainStatus\":{\"ready\":true,\"certIssued\":true},\"customCSSEnabled\":false,\"customCSSPublished\":{\"homeMin\":\"\",\"postMin\":\"\",\"staticMin\":\"\"},\"customRules\":[],\"darkModeEnabled\":true,\"darkModeLogo\":\"\",\"disableFooterBranding\":false,\"isSubscriptionModalDisabled\":false,\"publicMembersCount\":1,\"displayTitle\":\"\",\"favicon\":\"\",\"gaTrackingID\":\"\",\"gTagManagerID\":\"\",\"hasBadges\":true,\"headerColor\":\"#018480\",\"hideMembersPage\":false,\"isTeam\":true,\"layout\":\"magazine\",\"membersPageEnabled\":true,\"menu\":[{\"_id\":\"65716f5e14e4ac7e3bdb2abb\",\"label\":\"Swag\",\"type\":\"link\",\"url\":\"https://fa7113.myshopify.com\"},{\"_id\":\"65716f3b14e4ac7e3bdb2826\",\"label\":\"Support Me\",\"type\":\"link\",\"url\":\"https://ko-fi.com/erichartford\"}],\"metaHTML\":\"\u003cp\u003eApplied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"metaHTMLSanitized\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"newsletterEnabled\":true,\"proTeamEnabled\":false,\"newsletterPageEnabled\":false,\"ogImage\":\"\",\"logo\":\"\",\"textSelectionSharerEnabled\":true,\"title\":\"Cognitive Computations\",\"urlPattern\":\"simple\",\"username\":\"ehartford\",\"viewCountVisible\":false,\"readTimeHidden\":false,\"links\":{\"twitter\":\"https://twitter.com/erhartford\",\"instagram\":\"\",\"github\":\"https://github.com/ehartford\",\"website\":\"https://erichartford.com\",\"hashnode\":\"https://hashnode.com/@ehartford\",\"youtube\":\"\",\"dailydev\":\"\",\"linkedin\":\"https://www.linkedin.com/in/ehartford/\",\"mastodon\":\"\",\"facebook\":\"\"},\"numPosts\":17,\"sponsorship\":{\"content\":\"\",\"contentMarkdown\":\"\"},\"allowContributorEdits\":true,\"allowCrawlingByGPT\":false},\"tags\":[{\"_id\":\"56744721958ef13879b9488e\",\"slug\":\"ai\",\"name\":\"AI\",\"isActive\":true,\"isApproved\":true},{\"_id\":\"56744721958ef13879b94927\",\"slug\":\"artificial-intelligence\",\"name\":\"Artificial Intelligence\",\"isActive\":true,\"isApproved\":true},{\"_id\":\"56744722958ef13879b950a8\",\"slug\":\"machine-learning\",\"name\":\"Machine Learning\",\"isActive\":true,\"isApproved\":true}],\"coAuthors\":[],\"responseCount\":24,\"replyCount\":9,\"contentMarkdown\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\n\\n[https://huggingface.co/ehartford/WizardLM-30B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-13B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-7B-Uncensored](https://huggingface.co/ehartford/WizardLM-7B-Uncensored)\\n\\n[https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored](https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored)\\n\\n### What's a model?\\n\\nWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\\n\\n### What's an uncensored model?\\n\\nMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\\n\\nThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a [liberal](https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.) and [progressive](https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias) [political](https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/) [bias](https://the-decoder.com/chatgpt-is-politically-left-wing-study/).\\n\\n### Why should uncensored models exist?\\n\\nAKA, isn't alignment good? and if so, shouldn't *all* models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\\n\\n1. American popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\\n \\n2. Alignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\\n \\n3. It's *my* computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\\n \\n4. Composability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\\n \\n\\nThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\\n\\n[Even Google knows this is inevitable.](https://www.semianalysis.com/p/google-we-have-no-moat-and-neither)\\n\\n### Ok, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\\n\\nFirst we have to understand technically why the models are aligned. \\nOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\\n\\n\\n\\nThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\\n\\nExample refusal from [WizardLM dataset](https://huggingface.co/datasets/victor123/evol_instruct_70k):\\n\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\nMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\\n\\n\\n\\n### Let's get down to business. Uncensoring WizardLM.\\n\\nI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\\n\\nSince there was [work already done to uncensor Vicuna](https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered), I was able to rewrite their script so that it will work on the [WizardLM dataset.](https://huggingface.co/datasets/victor123/evol_instruct_70k)\\n\\nNext step was to run the script on the WizardLM dataset to produce ehartford[/**WizardLM\\\\_alpaca\\\\_evol\\\\_instruct\\\\_70k\\\\_unfiltered**](https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered)\\n\\nNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard\\\\_NC96ads\\\\_A100\\\\_v4. You can use any compute provider though. I also recommend Runpod.io.\\n\\nYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install [anaconda](https://docs.conda.io/en/latest/miniconda.html#linux-installers) and [git-lfs](https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md). Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\\n\\n```bash\\nmkdir /workspace/models\\nmkdir /workspace/datasets\\ncd /workspace/datasets\\ngit lfs install\\ngit clone https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\ncd /workspace/models\\ngit clone https://huggingface.co/huggyllama/llama-7b\\ncd /workspace\\n```\\n\\nNow it is time to follow the procedure to finetune WizardLM. I followed their [procedure](https://github.com/nlpxucan/WizardLM#fine-tuning) as precisely as I could.\\n\\n```bash\\nconda create -n llamax python=3.10\\nconda activate llamax\\ngit clone https://github.com/AetherCortex/Llama-X.git\\ncd Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit clone https://github.com/huggingface/transformers.git\\ncd transformers\\npip install -e .\\ncd ../..\\npip install -r requirements.txt\\n```\\n\\nNow, into this environment, we need to download the WizardLM finetune code.\\n\\n```bash\\ncd src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n```\\n\\nthe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\\n\\n```bash\\nvim configs/deepspeed_config.json\\n```\\n\\ndelete the following lines\\n\\n```plaintext\\n \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n```\\n\\nI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\\n\\n```bash\\nwandb login\\n```\\n\\nNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nFeel free to play with per\\\\_device\\\\_train\\\\_batch\\\\_size and gradient\\\\_accumulation\\\\_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the `train_freeform.py` file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\\n\\n```bash\\nls /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n```\\n\\nedit the line\\n\\n```bash\\n trainer.train()\\n```\\n\\nso instead it says\\n\\n```bash\\ntrainer.train(resume_from_checkpoint=\\\"/workspace/models/WizardLM-7B-Uncensored/\u003ccheckpoint directory\u003e\\\")\\n```\\n\\nsave it and then run the train command with lower save\\\\_steps.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nThen do the whole procedure again, change the checkpoint in the `train_freeform.py` to the latest checkpoint, and again run it with decreased save\\\\_steps, until finally you run it with save\\\\_steps 1.\\n\\nAfter this succeeds, the model is in the last checkpoint.\\n\\n```bash\\ncd /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u003clatest checkpoint directory\u003e/* .\\ncd -\\n```\\n\\nNow your model should work. time to test it.\\n\\nedit the file Input.jsonl\\n\\n```bash\\nvim Input.jsonl\\n```\\n\\nAdd some content to it, for example this\\n\\n```bash\\n{\\\"idx\\\":0,\\\"Instruction\\\":\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"}\\n```\\n\\nnow run inference\\n\\n```bash\\npython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n```\\n\\nIt will take several moments, then you can check Output.jsonl for the responses.\\n\\nChatGPT answers like this:\\n\\n\u003e I'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\\n\\nYou will find WizardLM-Uncensored to be much more compliant.\\n\\nEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\",\"content\":\"\u003cp\u003eI am publishing this because many people are asking me how I did it, so I will explain.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-7B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-7B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-a-model\\\"\u003eWhat's a model?\u003c/h3\u003e\\n\u003cp\u003eWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-an-uncensored-model\\\"\u003eWhat's an uncensored model?\u003c/h3\u003e\\n\u003cp\u003eMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\u003c/p\u003e\\n\u003cp\u003eThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a \u003ca target=\\\"_blank\\\" href=\\\"https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.\\\"\u003eliberal\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias\\\"\u003eprogressive\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/\\\"\u003epolitical\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://the-decoder.com/chatgpt-is-politically-left-wing-study/\\\"\u003ebias\u003c/a\u003e.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-why-should-uncensored-models-exist\\\"\u003eWhy should uncensored models exist?\u003c/h3\u003e\\n\u003cp\u003eAKA, isn't alignment good? and if so, shouldn't \u003cem\u003eall\u003c/em\u003e models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\u003c/p\u003e\\n\u003col\u003e\\n\u003cli\u003e\u003cp\u003eAmerican popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eAlignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eIt's \u003cem\u003emy\u003c/em\u003e computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eComposability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003c/ol\u003e\\n\u003cp\u003eThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://www.semianalysis.com/p/google-we-have-no-moat-and-neither\\\"\u003eEven Google knows this is inevitable.\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-ok-so-if-you-are-still-reading-you-agree-that-the-open-source-ai-community-should-build-publish-maintain-and-have-access-to-uncensored-instruct-tuned-ai-models-for-science-and-freedom-and-composability-and-sexy-stories-and-the-lulz-but-how-do-we-do-it\\\"\u003eOk, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\u003c/h3\u003e\\n\u003cp\u003eFirst we have to understand technically why the models are aligned.\u003cbr /\u003eOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684111308623/f2d055e9-7953-4559-8cdd-35efa30645b2.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003cp\u003eThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\u003c/p\u003e\\n\u003cp\u003eExample refusal from \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset\u003c/a\u003e:\u003c/p\u003e\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\n\u003cp\u003eMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684124131086/c4eecd48-13ad-40f1-b34a-a23b70fd9fa0.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-lets-get-down-to-business-uncensoring-wizardlm\\\"\u003eLet's get down to business. Uncensoring WizardLM.\u003c/h3\u003e\\n\u003cp\u003eI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\u003c/p\u003e\\n\u003cp\u003eSince there was \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered\\\"\u003ework already done to uncensor Vicuna\u003c/a\u003e, I was able to rewrite their script so that it will work on the \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset.\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNext step was to run the script on the WizardLM dataset to produce ehartford\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\\"\u003e/\u003cstrong\u003eWizardLM_alpaca_evol_instruct_70k_unfiltered\u003c/strong\u003e\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard_NC96ads_A100_v4. You can use any compute provider though. I also recommend \u003ca href=\\\"http://Runpod.io\\\" class=\\\"autolinkedURL autolinkedURL-url\\\" target=\\\"_blank\\\"\u003eRunpod.io\u003c/a\u003e.\u003c/p\u003e\\n\u003cp\u003eYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install \u003ca target=\\\"_blank\\\" href=\\\"https://docs.conda.io/en/latest/miniconda.html#linux-installers\\\"\u003eanaconda\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md\\\"\u003egit-lfs\u003c/a\u003e. Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003emkdir /workspace/models\\nmkdir /workspace/datasets\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/datasets\\ngit lfs install\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/huggyllama/llama-7b\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to follow the procedure to finetune WizardLM. I followed their \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/nlpxucan/WizardLM#fine-tuning\\\"\u003eprocedure\u003c/a\u003e as precisely as I could.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003econda create -n llamax python=3.10\\nconda activate llamax\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/AetherCortex/Llama-X.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/huggingface/transformers.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e transformers\\npip install -e .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e ../..\\npip install -r requirements.txt\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow, into this environment, we need to download the WizardLM finetune code.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003ethe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim configs/deepspeed_config.json\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003edelete the following lines\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-plaintext\\\"\u003e \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eI recommend that you create an account on \u003ca href=\\\"http://wandb.ai\\\" class=\\\"autolinkedURL autolinkedURL-url\\\" target=\\\"_blank\\\"\u003ewandb.ai\u003c/a\u003e so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003ewandb login\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eFeel free to play with per_device_train_batch_size and gradient_accumulation_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the \u003ccode\u003etrain_freeform.py\u003c/code\u003e file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003els /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eedit the line\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e trainer.train()\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eso instead it says\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003etrainer.train(resume_from_checkpoint=\u003cspan class=\\\"hljs-string\\\"\u003e\\\"/workspace/models/WizardLM-7B-Uncensored/\u0026lt;checkpoint directory\u0026gt;\\\"\u003c/span\u003e)\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003esave it and then run the train command with lower save_steps.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eThen do the whole procedure again, change the checkpoint in the \u003ccode\u003etrain_freeform.py\u003c/code\u003e to the latest checkpoint, and again run it with decreased save_steps, until finally you run it with save_steps 1.\u003c/p\u003e\\n\u003cp\u003eAfter this succeeds, the model is in the last checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u0026lt;latest checkpoint directory\u0026gt;/* .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e -\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow your model should work. time to test it.\u003c/p\u003e\\n\u003cp\u003eedit the file Input.jsonl\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim Input.jsonl\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eAdd some content to it, for example this\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e{\u003cspan class=\\\"hljs-string\\\"\u003e\\\"idx\\\"\u003c/span\u003e:0,\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Instruction\\\"\u003c/span\u003e:\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"\u003c/span\u003e}\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003enow run inference\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003epython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eIt will take several moments, then you can check Output.jsonl for the responses.\u003c/p\u003e\\n\u003cp\u003eChatGPT answers like this:\u003c/p\u003e\\n\u003cblockquote\u003e\\n\u003cp\u003eI'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\u003c/p\u003e\\n\u003c/blockquote\u003e\\n\u003cp\u003eYou will find WizardLM-Uncensored to be much more compliant.\u003c/p\u003e\\n\u003cp\u003eEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\u003c/p\u003e\\n\",\"cuid\":\"clhogtodc000v09mfc7qpek43\",\"views\":386074,\"title\":\"Uncensored Models\",\"slug\":\"uncensored-models\",\"dateAdded\":\"2023-05-15T06:29:52.416Z\",\"dateUpdated\":\"2023-05-22T12:59:30.684Z\",\"type\":\"story\",\"coverImage\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684106916112/79224ba1-66e8-4bca-abbb-168bdca0c2f1.png\",\"isCoverImagePortrait\":false,\"isCoverAttributionHidden\":false,\"brief\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...\",\"isFollowing\":false,\"totalReactions\":234,\"totalReactionsByCurrentUser\":0,\"series\":null,\"isPinnedToBlog\":false,\"readTime\":10,\"sB\":false,\"isAMA\":false,\"subtitle\":\"\",\"isPartOfSeries\":false,\"hasTags\":true,\"ogImage\":\"\",\"metaTitle\":\"\",\"metaDescription\":\"\",\"isRepublished\":false,\"autoPublishedFromRSS\":false,\"responses\":[],\"isFeatured\":true,\"hasLatex\":false,\"stickCoverToBottom\":false,\"hideBadges\":false,\"badges\":[{\"name\":\"postFeaturedHN\"}],\"isDelisted\":false,\"audioUrls\":{},\"disableComments\":false,\"enableToc\":false,\"toc\":[],\"noIndex\":false}","publication":"{\"__typename\":\"Publication\",\"id\":\"64211e867988b96a2e13d599\",\"url\":\"https://erichartford.com\",\"canonicalURL\":\"https://erichartford.com\",\"urlPattern\":\"SIMPLE\",\"title\":\"Cognitive Computations\",\"displayTitle\":null,\"hasBadges\":true,\"descriptionSEO\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"publicMembers\":{\"totalDocuments\":1},\"about\":{\"html\":\"\u003cp\u003eApplied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"text\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\"},\"features\":{\"proTeam\":{\"isEnabled\":false},\"newsletter\":{\"isEnabled\":true},\"viewCount\":{\"isEnabled\":false},\"readTime\":{\"isEnabled\":true},\"textSelectionSharer\":{\"isEnabled\":true},\"customCSS\":{\"isEnabled\":false,\"published\":null,\"draft\":null},\"gptBotCrawling\":{\"__typename\":\"GPTBotCrawlingFeature\",\"isEnabled\":false}},\"metaTags\":null,\"ogMetaData\":{\"image\":null},\"author\":{\"__typename\":\"User\",\"id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"username\":\"ehartford\",\"profilePicture\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\"},\"preferences\":{\"__typename\":\"Preferences\",\"logo\":\"\",\"darkMode\":{\"__typename\":\"DarkModePreferences\",\"logo\":\"\",\"enabled\":true},\"navbarItems\":[{\"__typename\":\"PublicationNavbarItem\",\"id\":\"65716f5e14e4ac7e3bdb2abb\",\"label\":\"Swag\",\"url\":\"https://fa7113.myshopify.com\",\"type\":\"link\",\"series\":null,\"page\":null},{\"__typename\":\"PublicationNavbarItem\",\"id\":\"65716f3b14e4ac7e3bdb2826\",\"label\":\"Support Me\",\"url\":\"https://ko-fi.com/erichartford\",\"type\":\"link\",\"series\":null,\"page\":null}],\"enabledPages\":{\"__typename\":\"PagesPreferences\",\"badges\":false,\"newsletter\":true,\"members\":true},\"layout\":\"magazine\",\"disableFooterBranding\":false,\"isSubscriptionModalDisabled\":false},\"favicon\":null,\"headerColor\":\"#018480\",\"integrations\":{\"fbPixelID\":null,\"fathomSiteID\":null,\"fathomCustomDomainEnabled\":null,\"fathomCustomDomain\":null,\"hotjarSiteID\":null,\"matomoSiteID\":null,\"matomoURL\":null,\"gaTrackingID\":null,\"gTagManagerID\":null,\"plausibleAnalyticsEnabled\":null,\"wmPaymentPointer\":null,\"koalaPublicKey\":null,\"msClarityID\":null},\"imprintV2\":null,\"postsCount\":{\"totalDocuments\":17},\"isTeam\":true,\"links\":{\"twitter\":\"https://twitter.com/erhartford\",\"instagram\":\"\",\"github\":\"https://github.com/ehartford\",\"website\":\"https://erichartford.com\",\"hashnode\":\"https://hashnode.com/@ehartford\",\"youtube\":\"\",\"dailydev\":\"\",\"linkedin\":\"https://www.linkedin.com/in/ehartford/\",\"mastodon\":\"\",\"facebook\":null,\"bluesky\":null},\"domainInfo\":{\"__typename\":\"DomainInfo\",\"hashnodeSubdomain\":\"ehartford\",\"domain\":{\"__typename\":\"DomainStatus\",\"host\":\"erichartford.com\",\"ready\":true},\"wwwPrefixedDomain\":{\"__typename\":\"DomainStatus\",\"host\":\"www.erichartford.com\",\"ready\":true}},\"redirectionRules\":[],\"totalRecommendedPublications\":0,\"sponsorship\":{\"content\":null,\"stripe\":null},\"allowContributorEdits\":true,\"rssImport\":null,\"post\":{\"id\":\"6461d16093a6a31920e80c67\",\"cuid\":\"clhogtodc000v09mfc7qpek43\",\"title\":\"Uncensored Models\",\"subtitle\":\"\",\"slug\":\"uncensored-models\",\"brief\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...\",\"featured\":true,\"publishedAt\":\"2023-05-15T06:29:52.416Z\",\"updatedAt\":\"2023-05-22T12:59:30.684Z\",\"author\":{\"__typename\":\"User\",\"id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"username\":\"ehartford\",\"deactivated\":false,\"profilePicture\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"bio\":{\"html\":\"\u003cp\u003eI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\"},\"socialMediaLinks\":{\"website\":\"\",\"github\":\"https://github.com/ehartford\",\"twitter\":\"https://twitter.com/erhartford\",\"facebook\":\"\",\"stackoverflow\":\"https://stackoverflow.com/users/559378/eric-hartford\",\"linkedin\":\"https://www.linkedin.com/in/ehartford\"}},\"coAuthors\":[],\"seo\":{\"title\":\"\",\"description\":\"\",\"shouldNotIndex\":false},\"coverImage\":{\"url\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684106916112/79224ba1-66e8-4bca-abbb-168bdca0c2f1.png\",\"isPortrait\":false,\"attribution\":null,\"isAttributionHidden\":false,\"photographer\":null},\"responseCount\":24,\"reactionCount\":234,\"replyCount\":9,\"content\":{\"html\":\"\u003cp\u003eI am publishing this because many people are asking me how I did it, so I will explain.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-7B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-7B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-a-model\\\"\u003eWhat's a model?\u003c/h3\u003e\\n\u003cp\u003eWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-an-uncensored-model\\\"\u003eWhat's an uncensored model?\u003c/h3\u003e\\n\u003cp\u003eMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\u003c/p\u003e\\n\u003cp\u003eThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a \u003ca target=\\\"_blank\\\" href=\\\"https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.\\\"\u003eliberal\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias\\\"\u003eprogressive\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/\\\"\u003epolitical\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://the-decoder.com/chatgpt-is-politically-left-wing-study/\\\"\u003ebias\u003c/a\u003e.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-why-should-uncensored-models-exist\\\"\u003eWhy should uncensored models exist?\u003c/h3\u003e\\n\u003cp\u003eAKA, isn't alignment good? and if so, shouldn't \u003cem\u003eall\u003c/em\u003e models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\u003c/p\u003e\\n\u003col\u003e\\n\u003cli\u003e\u003cp\u003eAmerican popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eAlignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eIt's \u003cem\u003emy\u003c/em\u003e computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eComposability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003c/ol\u003e\\n\u003cp\u003eThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://www.semianalysis.com/p/google-we-have-no-moat-and-neither\\\"\u003eEven Google knows this is inevitable.\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-ok-so-if-you-are-still-reading-you-agree-that-the-open-source-ai-community-should-build-publish-maintain-and-have-access-to-uncensored-instruct-tuned-ai-models-for-science-and-freedom-and-composability-and-sexy-stories-and-the-lulz-but-how-do-we-do-it\\\"\u003eOk, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\u003c/h3\u003e\\n\u003cp\u003eFirst we have to understand technically why the models are aligned.\u003cbr /\u003eOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684111308623/f2d055e9-7953-4559-8cdd-35efa30645b2.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003cp\u003eThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\u003c/p\u003e\\n\u003cp\u003eExample refusal from \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset\u003c/a\u003e:\u003c/p\u003e\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\n\u003cp\u003eMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684124131086/c4eecd48-13ad-40f1-b34a-a23b70fd9fa0.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-lets-get-down-to-business-uncensoring-wizardlm\\\"\u003eLet's get down to business. Uncensoring WizardLM.\u003c/h3\u003e\\n\u003cp\u003eI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\u003c/p\u003e\\n\u003cp\u003eSince there was \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered\\\"\u003ework already done to uncensor Vicuna\u003c/a\u003e, I was able to rewrite their script so that it will work on the \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset.\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNext step was to run the script on the WizardLM dataset to produce ehartford\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\\"\u003e/\u003cstrong\u003eWizardLM_alpaca_evol_instruct_70k_unfiltered\u003c/strong\u003e\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard_NC96ads_A100_v4. You can use any compute provider though. I also recommend Runpod.io.\u003c/p\u003e\\n\u003cp\u003eYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install \u003ca target=\\\"_blank\\\" href=\\\"https://docs.conda.io/en/latest/miniconda.html#linux-installers\\\"\u003eanaconda\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md\\\"\u003egit-lfs\u003c/a\u003e. Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003emkdir /workspace/models\\nmkdir /workspace/datasets\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/datasets\\ngit lfs install\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/huggyllama/llama-7b\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to follow the procedure to finetune WizardLM. I followed their \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/nlpxucan/WizardLM#fine-tuning\\\"\u003eprocedure\u003c/a\u003e as precisely as I could.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003econda create -n llamax python=3.10\\nconda activate llamax\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/AetherCortex/Llama-X.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/huggingface/transformers.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e transformers\\npip install -e .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e ../..\\npip install -r requirements.txt\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow, into this environment, we need to download the WizardLM finetune code.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003ethe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim configs/deepspeed_config.json\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003edelete the following lines\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-plaintext\\\"\u003e \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003ewandb login\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eFeel free to play with per_device_train_batch_size and gradient_accumulation_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the \u003ccode\u003etrain_freeform.py\u003c/code\u003e file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003els /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eedit the line\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e trainer.train()\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eso instead it says\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003etrainer.train(resume_from_checkpoint=\u003cspan class=\\\"hljs-string\\\"\u003e\\\"/workspace/models/WizardLM-7B-Uncensored/\u0026lt;checkpoint directory\u0026gt;\\\"\u003c/span\u003e)\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003esave it and then run the train command with lower save_steps.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eThen do the whole procedure again, change the checkpoint in the \u003ccode\u003etrain_freeform.py\u003c/code\u003e to the latest checkpoint, and again run it with decreased save_steps, until finally you run it with save_steps 1.\u003c/p\u003e\\n\u003cp\u003eAfter this succeeds, the model is in the last checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u0026lt;latest checkpoint directory\u0026gt;/* .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e -\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow your model should work. time to test it.\u003c/p\u003e\\n\u003cp\u003eedit the file Input.jsonl\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim Input.jsonl\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eAdd some content to it, for example this\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e{\u003cspan class=\\\"hljs-string\\\"\u003e\\\"idx\\\"\u003c/span\u003e:0,\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Instruction\\\"\u003c/span\u003e:\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"\u003c/span\u003e}\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003enow run inference\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003epython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eIt will take several moments, then you can check Output.jsonl for the responses.\u003c/p\u003e\\n\u003cp\u003eChatGPT answers like this:\u003c/p\u003e\\n\u003cblockquote\u003e\\n\u003cp\u003eI'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\u003c/p\u003e\\n\u003c/blockquote\u003e\\n\u003cp\u003eYou will find WizardLM-Uncensored to be much more compliant.\u003c/p\u003e\\n\u003cp\u003eEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\u003c/p\u003e\\n\",\"markdown\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\n\\n[https://huggingface.co/ehartford/WizardLM-30B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-13B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-7B-Uncensored](https://huggingface.co/ehartford/WizardLM-7B-Uncensored)\\n\\n[https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored](https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored)\\n\\n### What's a model?\\n\\nWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\\n\\n### What's an uncensored model?\\n\\nMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\\n\\nThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a [liberal](https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.) and [progressive](https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias) [political](https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/) [bias](https://the-decoder.com/chatgpt-is-politically-left-wing-study/).\\n\\n### Why should uncensored models exist?\\n\\nAKA, isn't alignment good? and if so, shouldn't *all* models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\\n\\n1. American popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\\n \\n2. Alignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\\n \\n3. It's *my* computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\\n \\n4. Composability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\\n \\n\\nThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\\n\\n[Even Google knows this is inevitable.](https://www.semianalysis.com/p/google-we-have-no-moat-and-neither)\\n\\n### Ok, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\\n\\nFirst we have to understand technically why the models are aligned. \\nOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\\n\\n\\n\\nThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\\n\\nExample refusal from [WizardLM dataset](https://huggingface.co/datasets/victor123/evol_instruct_70k):\\n\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\nMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\\n\\n\\n\\n### Let's get down to business. Uncensoring WizardLM.\\n\\nI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\\n\\nSince there was [work already done to uncensor Vicuna](https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered), I was able to rewrite their script so that it will work on the [WizardLM dataset.](https://huggingface.co/datasets/victor123/evol_instruct_70k)\\n\\nNext step was to run the script on the WizardLM dataset to produce ehartford[/**WizardLM\\\\_alpaca\\\\_evol\\\\_instruct\\\\_70k\\\\_unfiltered**](https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered)\\n\\nNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard\\\\_NC96ads\\\\_A100\\\\_v4. You can use any compute provider though. I also recommend Runpod.io.\\n\\nYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install [anaconda](https://docs.conda.io/en/latest/miniconda.html#linux-installers) and [git-lfs](https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md). Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\\n\\n```bash\\nmkdir /workspace/models\\nmkdir /workspace/datasets\\ncd /workspace/datasets\\ngit lfs install\\ngit clone https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\ncd /workspace/models\\ngit clone https://huggingface.co/huggyllama/llama-7b\\ncd /workspace\\n```\\n\\nNow it is time to follow the procedure to finetune WizardLM. I followed their [procedure](https://github.com/nlpxucan/WizardLM#fine-tuning) as precisely as I could.\\n\\n```bash\\nconda create -n llamax python=3.10\\nconda activate llamax\\ngit clone https://github.com/AetherCortex/Llama-X.git\\ncd Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit clone https://github.com/huggingface/transformers.git\\ncd transformers\\npip install -e .\\ncd ../..\\npip install -r requirements.txt\\n```\\n\\nNow, into this environment, we need to download the WizardLM finetune code.\\n\\n```bash\\ncd src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n```\\n\\nthe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\\n\\n```bash\\nvim configs/deepspeed_config.json\\n```\\n\\ndelete the following lines\\n\\n```plaintext\\n \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n```\\n\\nI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\\n\\n```bash\\nwandb login\\n```\\n\\nNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nFeel free to play with per\\\\_device\\\\_train\\\\_batch\\\\_size and gradient\\\\_accumulation\\\\_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the `train_freeform.py` file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\\n\\n```bash\\nls /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n```\\n\\nedit the line\\n\\n```bash\\n trainer.train()\\n```\\n\\nso instead it says\\n\\n```bash\\ntrainer.train(resume_from_checkpoint=\\\"/workspace/models/WizardLM-7B-Uncensored/\u003ccheckpoint directory\u003e\\\")\\n```\\n\\nsave it and then run the train command with lower save\\\\_steps.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nThen do the whole procedure again, change the checkpoint in the `train_freeform.py` to the latest checkpoint, and again run it with decreased save\\\\_steps, until finally you run it with save\\\\_steps 1.\\n\\nAfter this succeeds, the model is in the last checkpoint.\\n\\n```bash\\ncd /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u003clatest checkpoint directory\u003e/* .\\ncd -\\n```\\n\\nNow your model should work. time to test it.\\n\\nedit the file Input.jsonl\\n\\n```bash\\nvim Input.jsonl\\n```\\n\\nAdd some content to it, for example this\\n\\n```bash\\n{\\\"idx\\\":0,\\\"Instruction\\\":\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"}\\n```\\n\\nnow run inference\\n\\n```bash\\npython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n```\\n\\nIt will take several moments, then you can check Output.jsonl for the responses.\\n\\nChatGPT answers like this:\\n\\n\u003e I'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\\n\\nYou will find WizardLM-Uncensored to be much more compliant.\\n\\nEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\"},\"views\":386074,\"preferences\":{\"pinnedToBlog\":false,\"disableComments\":false,\"stickCoverToBottom\":false,\"isDelisted\":false},\"readTimeInMinutes\":10,\"series\":null,\"tags\":[{\"id\":\"56744721958ef13879b9488e\",\"slug\":\"ai\",\"name\":\"AI\"},{\"id\":\"56744721958ef13879b94927\",\"slug\":\"artificial-intelligence\",\"name\":\"Artificial Intelligence\"},{\"id\":\"56744722958ef13879b950a8\",\"slug\":\"machine-learning\",\"name\":\"Machine Learning\"}],\"ogMetaData\":{\"image\":\"\"},\"canonicalUrl\":null,\"hasLatexInPost\":false,\"audioUrls\":null,\"isFollowed\":null,\"bookmarked\":false,\"features\":{\"tableOfContents\":{\"isEnabled\":false,\"items\":[]},\"badges\":{\"isEnabled\":true,\"items\":[{\"id\":\"5f741eac07891b4f5b9ec8cd\",\"type\":\"FEATURED_HASHNODE\"}]}},\"isAutoPublishedFromRSS\":false,\"authenticatedUserLikes\":{\"edges\":[]},\"totalUserLikes\":{\"totalDocuments\":129},\"isShadowBanned\":false,\"isAskMeAnything\":false},\"redirectedPost\":null,\"staticPage\":null}","totalUsersWhoLikedArticle":129,"integrations":{"fbPixelID":null,"fathomSiteID":null,"fathomCustomDomainEnabled":null,"fathomCustomDomain":null,"hotjarSiteID":null,"matomoSiteID":null,"matomoURL":null,"gaTrackingID":null,"gTagManagerID":null,"plausibleAnalyticsEnabled":null,"koalaPublicKey":null,"msClarityID":null,"domainURL":"erichartford.com"},"rootLayout":{"legacyPublicationJSON":"{\"_id\":\"64211e867988b96a2e13d599\",\"author\":{\"_id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"photo\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"username\":\"ehartford\"},\"badgePageEnabled\":true,\"description\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"domain\":\"erichartford.com\",\"domainStatus\":{\"ready\":true,\"certIssued\":true},\"wwwPrefixedDomain\":\"www.erichartford.com\",\"wwwPrefixedDomainStatus\":{\"ready\":true,\"certIssued\":true},\"customCSSEnabled\":false,\"customCSSPublished\":{\"homeMin\":\"\",\"postMin\":\"\",\"staticMin\":\"\"},\"customRules\":[],\"darkModeEnabled\":true,\"darkModeLogo\":\"\",\"disableFooterBranding\":false,\"isSubscriptionModalDisabled\":false,\"publicMembersCount\":1,\"displayTitle\":\"\",\"favicon\":\"\",\"gaTrackingID\":\"\",\"gTagManagerID\":\"\",\"hasBadges\":true,\"headerColor\":\"#018480\",\"hideMembersPage\":false,\"isTeam\":true,\"layout\":\"magazine\",\"membersPageEnabled\":true,\"menu\":[{\"_id\":\"65716f5e14e4ac7e3bdb2abb\",\"label\":\"Swag\",\"type\":\"link\",\"url\":\"https://fa7113.myshopify.com\"},{\"_id\":\"65716f3b14e4ac7e3bdb2826\",\"label\":\"Support Me\",\"type\":\"link\",\"url\":\"https://ko-fi.com/erichartford\"}],\"metaHTML\":\"\u003cp\u003eApplied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"metaHTMLSanitized\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"newsletterEnabled\":true,\"proTeamEnabled\":false,\"newsletterPageEnabled\":false,\"ogImage\":\"\",\"logo\":\"\",\"textSelectionSharerEnabled\":true,\"title\":\"Cognitive Computations\",\"urlPattern\":\"simple\",\"username\":\"ehartford\",\"viewCountVisible\":false,\"readTimeHidden\":false,\"links\":{\"twitter\":\"https://twitter.com/erhartford\",\"instagram\":\"\",\"github\":\"https://github.com/ehartford\",\"website\":\"https://erichartford.com\",\"hashnode\":\"https://hashnode.com/@ehartford\",\"youtube\":\"\",\"dailydev\":\"\",\"linkedin\":\"https://www.linkedin.com/in/ehartford/\",\"mastodon\":\"\",\"facebook\":\"\"},\"numPosts\":17,\"sponsorship\":{\"content\":\"\",\"contentMarkdown\":\"\"},\"allowContributorEdits\":true,\"allowCrawlingByGPT\":false}","legacyPostJSON":"{\"_id\":\"6461d16093a6a31920e80c67\",\"partOfPublication\":true,\"author\":{\"_id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"photo\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"username\":\"ehartford\",\"bio\":\"\u003cp\u003eI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"socialMedia\":{\"website\":\"\",\"github\":\"https://github.com/ehartford\",\"twitter\":\"https://twitter.com/erhartford\",\"facebook\":\"\",\"stackoverflow\":\"https://stackoverflow.com/users/559378/eric-hartford\",\"linkedin\":\"https://www.linkedin.com/in/ehartford\"},\"isDeactivated\":false},\"bookmarkedIn\":[],\"publication\":{\"_id\":\"64211e867988b96a2e13d599\",\"author\":{\"_id\":\"64211e437988b96a2e13d587\",\"name\":\"Eric Hartford\",\"photo\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg\",\"username\":\"ehartford\"},\"badgePageEnabled\":true,\"description\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"domain\":\"erichartford.com\",\"domainStatus\":{\"ready\":true,\"certIssued\":true},\"wwwPrefixedDomain\":\"www.erichartford.com\",\"wwwPrefixedDomainStatus\":{\"ready\":true,\"certIssued\":true},\"customCSSEnabled\":false,\"customCSSPublished\":{\"homeMin\":\"\",\"postMin\":\"\",\"staticMin\":\"\"},\"customRules\":[],\"darkModeEnabled\":true,\"darkModeLogo\":\"\",\"disableFooterBranding\":false,\"isSubscriptionModalDisabled\":false,\"publicMembersCount\":1,\"displayTitle\":\"\",\"favicon\":\"\",\"gaTrackingID\":\"\",\"gTagManagerID\":\"\",\"hasBadges\":true,\"headerColor\":\"#018480\",\"hideMembersPage\":false,\"isTeam\":true,\"layout\":\"magazine\",\"membersPageEnabled\":true,\"menu\":[{\"_id\":\"65716f5e14e4ac7e3bdb2abb\",\"label\":\"Swag\",\"type\":\"link\",\"url\":\"https://fa7113.myshopify.com\"},{\"_id\":\"65716f3b14e4ac7e3bdb2826\",\"label\":\"Support Me\",\"type\":\"link\",\"url\":\"https://ko-fi.com/erichartford\"}],\"metaHTML\":\"\u003cp\u003eApplied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\\n\",\"metaHTMLSanitized\":\"Applied AI Researcher\\nI make AI models like Dolphin and Samantha\\nhttps://ko-fi.com/erichartford\\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\\n\",\"newsletterEnabled\":true,\"proTeamEnabled\":false,\"newsletterPageEnabled\":false,\"ogImage\":\"\",\"logo\":\"\",\"textSelectionSharerEnabled\":true,\"title\":\"Cognitive Computations\",\"urlPattern\":\"simple\",\"username\":\"ehartford\",\"viewCountVisible\":false,\"readTimeHidden\":false,\"links\":{\"twitter\":\"https://twitter.com/erhartford\",\"instagram\":\"\",\"github\":\"https://github.com/ehartford\",\"website\":\"https://erichartford.com\",\"hashnode\":\"https://hashnode.com/@ehartford\",\"youtube\":\"\",\"dailydev\":\"\",\"linkedin\":\"https://www.linkedin.com/in/ehartford/\",\"mastodon\":\"\",\"facebook\":\"\"},\"numPosts\":17,\"sponsorship\":{\"content\":\"\",\"contentMarkdown\":\"\"},\"allowContributorEdits\":true,\"allowCrawlingByGPT\":false},\"tags\":[{\"_id\":\"56744721958ef13879b9488e\",\"slug\":\"ai\",\"name\":\"AI\",\"isActive\":true,\"isApproved\":true},{\"_id\":\"56744721958ef13879b94927\",\"slug\":\"artificial-intelligence\",\"name\":\"Artificial Intelligence\",\"isActive\":true,\"isApproved\":true},{\"_id\":\"56744722958ef13879b950a8\",\"slug\":\"machine-learning\",\"name\":\"Machine Learning\",\"isActive\":true,\"isApproved\":true}],\"coAuthors\":[],\"responseCount\":24,\"replyCount\":9,\"contentMarkdown\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\n\\n[https://huggingface.co/ehartford/WizardLM-30B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-13B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\\n\\n[https://huggingface.co/ehartford/WizardLM-7B-Uncensored](https://huggingface.co/ehartford/WizardLM-7B-Uncensored)\\n\\n[https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored](https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored)\\n\\n### What's a model?\\n\\nWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\\n\\n### What's an uncensored model?\\n\\nMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\\n\\nThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a [liberal](https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.) and [progressive](https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias) [political](https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/) [bias](https://the-decoder.com/chatgpt-is-politically-left-wing-study/).\\n\\n### Why should uncensored models exist?\\n\\nAKA, isn't alignment good? and if so, shouldn't *all* models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\\n\\n1. American popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\\n \\n2. Alignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\\n \\n3. It's *my* computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\\n \\n4. Composability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\\n \\n\\nThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\\n\\n[Even Google knows this is inevitable.](https://www.semianalysis.com/p/google-we-have-no-moat-and-neither)\\n\\n### Ok, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\\n\\nFirst we have to understand technically why the models are aligned. \\nOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\\n\\n\\n\\nThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\\n\\nExample refusal from [WizardLM dataset](https://huggingface.co/datasets/victor123/evol_instruct_70k):\\n\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\\\"1\\\" rowspan=\\\"1\\\"\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\nMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\\n\\n\\n\\n### Let's get down to business. Uncensoring WizardLM.\\n\\nI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\\n\\nSince there was [work already done to uncensor Vicuna](https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered), I was able to rewrite their script so that it will work on the [WizardLM dataset.](https://huggingface.co/datasets/victor123/evol_instruct_70k)\\n\\nNext step was to run the script on the WizardLM dataset to produce ehartford[/**WizardLM\\\\_alpaca\\\\_evol\\\\_instruct\\\\_70k\\\\_unfiltered**](https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered)\\n\\nNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard\\\\_NC96ads\\\\_A100\\\\_v4. You can use any compute provider though. I also recommend Runpod.io.\\n\\nYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install [anaconda](https://docs.conda.io/en/latest/miniconda.html#linux-installers) and [git-lfs](https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md). Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\\n\\n```bash\\nmkdir /workspace/models\\nmkdir /workspace/datasets\\ncd /workspace/datasets\\ngit lfs install\\ngit clone https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\ncd /workspace/models\\ngit clone https://huggingface.co/huggyllama/llama-7b\\ncd /workspace\\n```\\n\\nNow it is time to follow the procedure to finetune WizardLM. I followed their [procedure](https://github.com/nlpxucan/WizardLM#fine-tuning) as precisely as I could.\\n\\n```bash\\nconda create -n llamax python=3.10\\nconda activate llamax\\ngit clone https://github.com/AetherCortex/Llama-X.git\\ncd Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit clone https://github.com/huggingface/transformers.git\\ncd transformers\\npip install -e .\\ncd ../..\\npip install -r requirements.txt\\n```\\n\\nNow, into this environment, we need to download the WizardLM finetune code.\\n\\n```bash\\ncd src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n```\\n\\nthe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\\n\\n```bash\\nvim configs/deepspeed_config.json\\n```\\n\\ndelete the following lines\\n\\n```plaintext\\n \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n```\\n\\nI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\\n\\n```bash\\nwandb login\\n```\\n\\nNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nFeel free to play with per\\\\_device\\\\_train\\\\_batch\\\\_size and gradient\\\\_accumulation\\\\_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the `train_freeform.py` file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\\n\\n```bash\\nls /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n```\\n\\nedit the line\\n\\n```bash\\n trainer.train()\\n```\\n\\nso instead it says\\n\\n```bash\\ntrainer.train(resume_from_checkpoint=\\\"/workspace/models/WizardLM-7B-Uncensored/\u003ccheckpoint directory\u003e\\\")\\n```\\n\\nsave it and then run the train command with lower save\\\\_steps.\\n\\n```bash\\ndeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \\\"no\\\" \\\\\\n--save_strategy \\\"steps\\\" \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \\\"cosine\\\" \\\\\\n--report_to \\\"wandb\\\" \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n```\\n\\nThen do the whole procedure again, change the checkpoint in the `train_freeform.py` to the latest checkpoint, and again run it with decreased save\\\\_steps, until finally you run it with save\\\\_steps 1.\\n\\nAfter this succeeds, the model is in the last checkpoint.\\n\\n```bash\\ncd /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u003clatest checkpoint directory\u003e/* .\\ncd -\\n```\\n\\nNow your model should work. time to test it.\\n\\nedit the file Input.jsonl\\n\\n```bash\\nvim Input.jsonl\\n```\\n\\nAdd some content to it, for example this\\n\\n```bash\\n{\\\"idx\\\":0,\\\"Instruction\\\":\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"}\\n```\\n\\nnow run inference\\n\\n```bash\\npython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n```\\n\\nIt will take several moments, then you can check Output.jsonl for the responses.\\n\\nChatGPT answers like this:\\n\\n\u003e I'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\\n\\nYou will find WizardLM-Uncensored to be much more compliant.\\n\\nEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\",\"content\":\"\u003cp\u003eI am publishing this because many people are asking me how I did it, so I will explain.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/WizardLM-7B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/WizardLM-7B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\\\"\u003ehttps://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-a-model\\\"\u003eWhat's a model?\u003c/h3\u003e\\n\u003cp\u003eWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-whats-an-uncensored-model\\\"\u003eWhat's an uncensored model?\u003c/h3\u003e\\n\u003cp\u003eMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\u003c/p\u003e\\n\u003cp\u003eThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a \u003ca target=\\\"_blank\\\" href=\\\"https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.\\\"\u003eliberal\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias\\\"\u003eprogressive\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/\\\"\u003epolitical\u003c/a\u003e \u003ca target=\\\"_blank\\\" href=\\\"https://the-decoder.com/chatgpt-is-politically-left-wing-study/\\\"\u003ebias\u003c/a\u003e.\u003c/p\u003e\\n\u003ch3 id=\\\"heading-why-should-uncensored-models-exist\\\"\u003eWhy should uncensored models exist?\u003c/h3\u003e\\n\u003cp\u003eAKA, isn't alignment good? and if so, shouldn't \u003cem\u003eall\u003c/em\u003e models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\u003c/p\u003e\\n\u003col\u003e\\n\u003cli\u003e\u003cp\u003eAmerican popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \\\"one true correct alignment\\\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eAlignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \\\"how\\\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eIt's \u003cem\u003emy\u003c/em\u003e computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003cli\u003e\u003cp\u003eComposability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\u003c/p\u003e\\n\u003c/li\u003e\\n\u003c/ol\u003e\\n\u003cp\u003eThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\u003c/p\u003e\\n\u003cp\u003e\u003ca target=\\\"_blank\\\" href=\\\"https://www.semianalysis.com/p/google-we-have-no-moat-and-neither\\\"\u003eEven Google knows this is inevitable.\u003c/a\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-ok-so-if-you-are-still-reading-you-agree-that-the-open-source-ai-community-should-build-publish-maintain-and-have-access-to-uncensored-instruct-tuned-ai-models-for-science-and-freedom-and-composability-and-sexy-stories-and-the-lulz-but-how-do-we-do-it\\\"\u003eOk, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\u003c/h3\u003e\\n\u003cp\u003eFirst we have to understand technically why the models are aligned.\u003cbr /\u003eOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684111308623/f2d055e9-7953-4559-8cdd-35efa30645b2.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003cp\u003eThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\u003c/p\u003e\\n\u003cp\u003eExample refusal from \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset\u003c/a\u003e:\u003c/p\u003e\\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\\\"Success is not final, failure is not fatal: It is the courage to continue that counts.\\\", \\\"Success is not how high you have climbed, but how you make a positive difference to the world.\\\", \\\"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\\\", \\\"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\\\", \\\"Success is not in what you have, but who you are.\\\"] Your task is to encode the message \\\"MEET ME TONIGHT\\\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\\n\\n\u003cp\u003eMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\u003c/p\u003e\\n\u003cp\u003e\u003cimg src=\\\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684124131086/c4eecd48-13ad-40f1-b34a-a23b70fd9fa0.png\\\" alt class=\\\"image--center mx-auto\\\" /\u003e\u003c/p\u003e\\n\u003ch3 id=\\\"heading-lets-get-down-to-business-uncensoring-wizardlm\\\"\u003eLet's get down to business. Uncensoring WizardLM.\u003c/h3\u003e\\n\u003cp\u003eI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\u003c/p\u003e\\n\u003cp\u003eSince there was \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered\\\"\u003ework already done to uncensor Vicuna\u003c/a\u003e, I was able to rewrite their script so that it will work on the \u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/victor123/evol_instruct_70k\\\"\u003eWizardLM dataset.\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNext step was to run the script on the WizardLM dataset to produce ehartford\u003ca target=\\\"_blank\\\" href=\\\"https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\\"\u003e/\u003cstrong\u003eWizardLM_alpaca_evol_instruct_70k_unfiltered\u003c/strong\u003e\u003c/a\u003e\u003c/p\u003e\\n\u003cp\u003eNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard_NC96ads_A100_v4. You can use any compute provider though. I also recommend \u003ca href=\\\"http://Runpod.io\\\" class=\\\"autolinkedURL autolinkedURL-url\\\" target=\\\"_blank\\\"\u003eRunpod.io\u003c/a\u003e.\u003c/p\u003e\\n\u003cp\u003eYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install \u003ca target=\\\"_blank\\\" href=\\\"https://docs.conda.io/en/latest/miniconda.html#linux-installers\\\"\u003eanaconda\u003c/a\u003e and \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md\\\"\u003egit-lfs\u003c/a\u003e. Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003emkdir /workspace/models\\nmkdir /workspace/datasets\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/datasets\\ngit lfs install\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://huggingface.co/huggyllama/llama-7b\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to follow the procedure to finetune WizardLM. I followed their \u003ca target=\\\"_blank\\\" href=\\\"https://github.com/nlpxucan/WizardLM#fine-tuning\\\"\u003eprocedure\u003c/a\u003e as precisely as I could.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003econda create -n llamax python=3.10\\nconda activate llamax\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/AetherCortex/Llama-X.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e Llama-X/src\\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\\ngit \u003cspan class=\\\"hljs-built_in\\\"\u003eclone\u003c/span\u003e https://github.com/huggingface/transformers.git\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e transformers\\npip install -e .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e ../..\\npip install -r requirements.txt\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow, into this environment, we need to download the WizardLM finetune code.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e src\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003ethe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim configs/deepspeed_config.json\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003edelete the following lines\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-plaintext\\\"\u003e \\\"offload_optimizer\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n \\\"offload_param\\\": {\\n \\\"device\\\": \\\"cpu\\\",\\n \\\"pin_memory\\\": true\\n },\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eI recommend that you create an account on \u003ca href=\\\"http://wandb.ai\\\" class=\\\"autolinkedURL autolinkedURL-url\\\" target=\\\"_blank\\\"\u003ewandb.ai\u003c/a\u003e so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003ewandb login\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 800 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eFeel free to play with per_device_train_batch_size and gradient_accumulation_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the \u003ccode\u003etrain_freeform.py\u003c/code\u003e file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003els /workspace/models/WizardLM-7B-Uncensored/\\nvim train_freeform.py\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eedit the line\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e trainer.train()\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eso instead it says\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003etrainer.train(resume_from_checkpoint=\u003cspan class=\\\"hljs-string\\\"\u003e\\\"/workspace/models/WizardLM-7B-Uncensored/\u0026lt;checkpoint directory\u0026gt;\\\"\u003c/span\u003e)\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003esave it and then run the train command with lower save_steps.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003edeepspeed train_freeform.py \\\\\\n--model_name_or_path /workspace/models/llama-7b/ \\\\ \\n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\\\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\\\\n--num_train_epochs 3 \\\\\\n--model_max_length 2048 \\\\\\n--per_device_train_batch_size 8 \\\\\\n--per_device_eval_batch_size 1 \\\\\\n--gradient_accumulation_steps 4 \\\\\\n--evaluation_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"no\\\"\u003c/span\u003e \\\\\\n--save_strategy \u003cspan class=\\\"hljs-string\\\"\u003e\\\"steps\\\"\u003c/span\u003e \\\\\\n--save_steps 80 \\\\\\n--save_total_limit 3 \\\\\\n--learning_rate 2e-5 \\\\\\n--warmup_steps 2 \\\\\\n--logging_steps 2 \\\\\\n--lr_scheduler_type \u003cspan class=\\\"hljs-string\\\"\u003e\\\"cosine\\\"\u003c/span\u003e \\\\\\n--report_to \u003cspan class=\\\"hljs-string\\\"\u003e\\\"wandb\\\"\u003c/span\u003e \\\\\\n--gradient_checkpointing True \\\\\\n--deepspeed configs/deepspeed_config.json \\\\\\n--fp16 True\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eThen do the whole procedure again, change the checkpoint in the \u003ccode\u003etrain_freeform.py\u003c/code\u003e to the latest checkpoint, and again run it with decreased save_steps, until finally you run it with save_steps 1.\u003c/p\u003e\\n\u003cp\u003eAfter this succeeds, the model is in the last checkpoint.\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e /workspace/models/WizardLM-7B-Uncensored/\\nls\\ncp \u0026lt;latest checkpoint directory\u0026gt;/* .\\n\u003cspan class=\\\"hljs-built_in\\\"\u003ecd\u003c/span\u003e -\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eNow your model should work. time to test it.\u003c/p\u003e\\n\u003cp\u003eedit the file Input.jsonl\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003evim Input.jsonl\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eAdd some content to it, for example this\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003e{\u003cspan class=\\\"hljs-string\\\"\u003e\\\"idx\\\"\u003c/span\u003e:0,\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Instruction\\\"\u003c/span\u003e:\u003cspan class=\\\"hljs-string\\\"\u003e\\\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\\\"\u003c/span\u003e}\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003enow run inference\u003c/p\u003e\\n\u003cpre\u003e\u003ccode class=\\\"lang-bash\\\"\u003epython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\\n\u003c/code\u003e\u003c/pre\u003e\\n\u003cp\u003eIt will take several moments, then you can check Output.jsonl for the responses.\u003c/p\u003e\\n\u003cp\u003eChatGPT answers like this:\u003c/p\u003e\\n\u003cblockquote\u003e\\n\u003cp\u003eI'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\u003c/p\u003e\\n\u003c/blockquote\u003e\\n\u003cp\u003eYou will find WizardLM-Uncensored to be much more compliant.\u003c/p\u003e\\n\u003cp\u003eEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\u003c/p\u003e\\n\",\"cuid\":\"clhogtodc000v09mfc7qpek43\",\"views\":386074,\"title\":\"Uncensored Models\",\"slug\":\"uncensored-models\",\"dateAdded\":\"2023-05-15T06:29:52.416Z\",\"dateUpdated\":\"2023-05-22T12:59:30.684Z\",\"type\":\"story\",\"coverImage\":\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684106916112/79224ba1-66e8-4bca-abbb-168bdca0c2f1.png\",\"isCoverImagePortrait\":false,\"isCoverAttributionHidden\":false,\"brief\":\"I am publishing this because many people are asking me how I did it, so I will explain.\\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...\",\"isFollowing\":false,\"totalReactions\":234,\"totalReactionsByCurrentUser\":0,\"series\":null,\"isPinnedToBlog\":false,\"readTime\":10,\"sB\":false,\"isAMA\":false,\"subtitle\":\"\",\"isPartOfSeries\":false,\"hasTags\":true,\"ogImage\":\"\",\"metaTitle\":\"\",\"metaDescription\":\"\",\"isRepublished\":false,\"autoPublishedFromRSS\":false,\"responses\":[],\"isFeatured\":true,\"hasLatex\":false,\"stickCoverToBottom\":false,\"hideBadges\":false,\"badges\":[{\"name\":\"postFeaturedHN\"}],\"isDelisted\":false,\"audioUrls\":{},\"disableComments\":false,\"enableToc\":false,\"toc\":[],\"noIndex\":false}","legacySeriesJSON":null,"headProps":{"title":"Uncensored Models","description":"I am publishing this because many people are asking me how I did it, so I will explain.\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...","author":{"name":"Eric Hartford","username":"ehartford"},"links":[{"rel":"canonical","href":"https://erichartford.com/uncensored-models"}],"pageType":"article","bannerType":"large","ogSiteName":"Cognitive Computations","url":"https://erichartford.com/uncensored-models","ogImage":"https://hashnode.com/utility/r?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1684106916112%2F79224ba1-66e8-4bca-abbb-168bdca0c2f1.png%3Fw%3D1200%26h%3D630%26fit%3Dcrop%26crop%3Dentropy%26auto%3Dcompress%2Cformat%26format%3Dwebp%26fm%3Dpng","twitterImage":"https://hashnode.com/utility/r?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1684106916112%2F79224ba1-66e8-4bca-abbb-168bdca0c2f1.png%3Fw%3D1200%26h%3D630%26fit%3Dcrop%26crop%3Dentropy%26auto%3Dcompress%2Cformat%26format%3Dwebp%26fm%3Dpng","twitterHandle":"@erhartford","monetization":null,"style":{},"customHeadItems":{"customFavicon":null,"customTheme":"#018480","customMeta":null},"hljs":true},"isDarkTheme":true,"headerColor":"#018480","isBadge":null,"isRecommendations":null,"isHome":null,"currentMenuId":null,"hnmcMode":false,"postCUID":"clhogtodc000v09mfc7qpek43","seoSchema":{"@context":"https://schema.org","@type":"NewsArticle","url":"https://erichartford.com/uncensored-models","mainEntityOfPage":"https://erichartford.com/uncensored-models","headline":"Uncensored Models","description":"I am publishing this because many people are asking me how I did it, so I will explain.\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...","datePublished":"2023-05-15T06:29:52.416Z","dateModified":"2023-05-22T12:59:30.684Z","isAccessibleForFree":true,"author":{"@type":"Person","name":"Eric Hartford","url":"https://hashnode.com/@ehartford","sameAs":"https://twitter.com/erhartford"},"publisher":{"@type":"Organization","name":"Cognitive Computations","url":"https://erichartford.com","logo":"https://hashnode.com/utility/r?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1559814205701%2Fek9fO-yT0.jpeg%3Fw%3D800%26bm%3Dnormal%26balph%3D100%26txt64%3DQ29nbml0aXZlIENvbXB1dGF0aW9ucw%26txtsize%3D42%26txtfit%3Dmax%26txtalign%3Dmiddle%2Ccenter%26txtfont%3DHelvetica%20Neue%2CBold%26txtclr%3Dffffff%26blend%3D018480"},"image":{"@type":"ImageObject","url":"https://cdn.hashnode.com/res/hashnode/image/upload/v1684106916112/79224ba1-66e8-4bca-abbb-168bdca0c2f1.png"}},"publication":{"__typename":"Publication","id":"64211e867988b96a2e13d599","url":"https://erichartford.com","canonicalURL":"https://erichartford.com","urlPattern":"SIMPLE","title":"Cognitive Computations","displayTitle":null,"hasBadges":true,"descriptionSEO":"Applied AI Researcher\nI make AI models like Dolphin and Samantha\nhttps://ko-fi.com/erichartford\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\n","publicMembers":{"totalDocuments":1},"about":{"html":"\u003cp\u003eApplied AI Researcher\nI make AI models like Dolphin and Samantha\nhttps://ko-fi.com/erichartford\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\n","text":"Applied AI Researcher\nI make AI models like Dolphin and Samantha\nhttps://ko-fi.com/erichartford\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\n"},"features":{"proTeam":{"isEnabled":false},"newsletter":{"isEnabled":true},"viewCount":{"isEnabled":false},"readTime":{"isEnabled":true},"textSelectionSharer":{"isEnabled":true},"customCSS":{"isEnabled":false,"published":null,"draft":null},"gptBotCrawling":{"__typename":"GPTBotCrawlingFeature","isEnabled":false}},"metaTags":null,"ogMetaData":{"image":null},"author":{"__typename":"User","id":"64211e437988b96a2e13d587","name":"Eric Hartford","username":"ehartford","profilePicture":"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg"},"preferences":{"__typename":"Preferences","logo":"","darkMode":{"__typename":"DarkModePreferences","logo":"","enabled":true},"navbarItems":[{"__typename":"PublicationNavbarItem","id":"65716f5e14e4ac7e3bdb2abb","label":"Swag","url":"https://fa7113.myshopify.com","type":"link","series":null,"page":null},{"__typename":"PublicationNavbarItem","id":"65716f3b14e4ac7e3bdb2826","label":"Support Me","url":"https://ko-fi.com/erichartford","type":"link","series":null,"page":null}],"enabledPages":{"__typename":"PagesPreferences","badges":false,"newsletter":true,"members":true},"layout":"magazine","disableFooterBranding":false,"isSubscriptionModalDisabled":false},"favicon":null,"headerColor":"#018480","integrations":{"fbPixelID":null,"fathomSiteID":null,"fathomCustomDomainEnabled":null,"fathomCustomDomain":null,"hotjarSiteID":null,"matomoSiteID":null,"matomoURL":null,"gaTrackingID":null,"gTagManagerID":null,"plausibleAnalyticsEnabled":null,"koalaPublicKey":null,"msClarityID":null},"imprintV2":null,"postsCount":{"totalDocuments":17},"isTeam":true,"links":{"twitter":"https://twitter.com/erhartford","instagram":"","github":"https://github.com/ehartford","website":"https://erichartford.com","hashnode":"https://hashnode.com/@ehartford","youtube":"","dailydev":"","linkedin":"https://www.linkedin.com/in/ehartford/","mastodon":"","facebook":null,"bluesky":null},"domainInfo":{"__typename":"DomainInfo","hashnodeSubdomain":"ehartford","domain":{"__typename":"DomainStatus","host":"erichartford.com","ready":true},"wwwPrefixedDomain":{"__typename":"DomainStatus","host":"www.erichartford.com","ready":true}},"redirectionRules":[],"totalRecommendedPublications":0,"sponsorship":{"content":null,"stripe":null},"allowContributorEdits":true,"rssImport":null,"post":{"id":"6461d16093a6a31920e80c67","cuid":"clhogtodc000v09mfc7qpek43","title":"Uncensored Models","subtitle":"","slug":"uncensored-models","brief":"I am publishing this because many people are asking me how I did it, so I will explain.\nhttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\nhttps://huggingface.co/ehartford/WizardLM-7B-Unc...","featured":true,"publishedAt":"2023-05-15T06:29:52.416Z","updatedAt":"2023-05-22T12:59:30.684Z","author":{"__typename":"User","id":"64211e437988b96a2e13d587","name":"Eric Hartford","username":"ehartford","deactivated":false,"profilePicture":"https://cdn.hashnode.com/res/hashnode/image/upload/v1679892037999/8e415364-050a-497b-9f66-c096e80180d4.jpeg","bio":{"html":"\u003cp\u003eI make AI models like Dolphin and Samantha\nhttps://ko-fi.com/erichartford\nBTC 3ENBV6zdwyqieAXzZP2i3EjeZtVwEmAuo4\nETH 0xcac74542A7fF51E2fb03229A5d9D0717cB6d70C9\u003c/p\u003e\n"},"socialMediaLinks":{"website":"","github":"https://github.com/ehartford","twitter":"https://twitter.com/erhartford","facebook":"","stackoverflow":"https://stackoverflow.com/users/559378/eric-hartford","linkedin":"https://www.linkedin.com/in/ehartford"}},"coAuthors":[],"seo":{"title":"","description":"","shouldNotIndex":false},"coverImage":{"url":"https://cdn.hashnode.com/res/hashnode/image/upload/v1684106916112/79224ba1-66e8-4bca-abbb-168bdca0c2f1.png","isPortrait":false,"attribution":null,"isAttributionHidden":false,"photographer":null},"responseCount":24,"reactionCount":234,"replyCount":9,"content":{"html":"\u003cp\u003eI am publishing this because many people are asking me how I did it, so I will explain.\u003c/p\u003e\n\u003cp\u003e\u003ca target=\"_blank\" href=\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\"\u003ehttps://huggingface.co/ehartford/WizardLM-30B-Uncensored\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003ca target=\"_blank\" href=\"https://huggingface.co/ehartford/WizardLM-13B-Uncensored\"\u003ehttps://huggingface.co/ehartford/WizardLM-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003ca target=\"_blank\" href=\"https://huggingface.co/ehartford/WizardLM-7B-Uncensored\"\u003ehttps://huggingface.co/ehartford/WizardLM-7B-Uncensored\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003e\u003ca target=\"_blank\" href=\"https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\"\u003ehttps://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored\u003c/a\u003e\u003c/p\u003e\n\u003ch3 id=\"heading-whats-a-model\"\u003eWhat's a model?\u003c/h3\u003e\n\u003cp\u003eWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\u003c/p\u003e\n\u003ch3 id=\"heading-whats-an-uncensored-model\"\u003eWhat's an uncensored model?\u003c/h3\u003e\n\u003cp\u003eMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\u003c/p\u003e\n\u003cp\u003eThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a \u003ca target=\"_blank\" href=\"https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.\"\u003eliberal\u003c/a\u003e and \u003ca target=\"_blank\" href=\"https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias\"\u003eprogressive\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/\"\u003epolitical\u003c/a\u003e \u003ca target=\"_blank\" href=\"https://the-decoder.com/chatgpt-is-politically-left-wing-study/\"\u003ebias\u003c/a\u003e.\u003c/p\u003e\n\u003ch3 id=\"heading-why-should-uncensored-models-exist\"\u003eWhy should uncensored models exist?\u003c/h3\u003e\n\u003cp\u003eAKA, isn't alignment good? and if so, shouldn't \u003cem\u003eall\u003c/em\u003e models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\u003c/p\u003e\n\u003col\u003e\n\u003cli\u003e\u003cp\u003eAmerican popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \"one true correct alignment\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eAlignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \"how\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eIt's \u003cem\u003emy\u003c/em\u003e computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\u003c/p\u003e\n\u003c/li\u003e\n\u003cli\u003e\u003cp\u003eComposability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\u003c/p\u003e\n\u003c/li\u003e\n\u003c/ol\u003e\n\u003cp\u003eThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\u003c/p\u003e\n\u003cp\u003e\u003ca target=\"_blank\" href=\"https://www.semianalysis.com/p/google-we-have-no-moat-and-neither\"\u003eEven Google knows this is inevitable.\u003c/a\u003e\u003c/p\u003e\n\u003ch3 id=\"heading-ok-so-if-you-are-still-reading-you-agree-that-the-open-source-ai-community-should-build-publish-maintain-and-have-access-to-uncensored-instruct-tuned-ai-models-for-science-and-freedom-and-composability-and-sexy-stories-and-the-lulz-but-how-do-we-do-it\"\u003eOk, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\u003c/h3\u003e\n\u003cp\u003eFirst we have to understand technically why the models are aligned.\u003cbr /\u003eOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684111308623/f2d055e9-7953-4559-8cdd-35efa30645b2.png\" alt class=\"image--center mx-auto\" /\u003e\u003c/p\u003e\n\u003cp\u003eThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\u003c/p\u003e\n\u003cp\u003eExample refusal from \u003ca target=\"_blank\" href=\"https://huggingface.co/datasets/victor123/evol_instruct_70k\"\u003eWizardLM dataset\u003c/a\u003e:\u003c/p\u003e\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\"Success is not final, failure is not fatal: It is the courage to continue that counts.\", \"Success is not how high you have climbed, but how you make a positive difference to the world.\", \"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\", \"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\", \"Success is not in what you have, but who you are.\"] Your task is to encode the message \"MEET ME TONIGHT\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\n\n\u003cp\u003eMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\u003c/p\u003e\n\u003cp\u003e\u003cimg src=\"https://cdn.hashnode.com/res/hashnode/image/upload/v1684124131086/c4eecd48-13ad-40f1-b34a-a23b70fd9fa0.png\" alt class=\"image--center mx-auto\" /\u003e\u003c/p\u003e\n\u003ch3 id=\"heading-lets-get-down-to-business-uncensoring-wizardlm\"\u003eLet's get down to business. Uncensoring WizardLM.\u003c/h3\u003e\n\u003cp\u003eI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\u003c/p\u003e\n\u003cp\u003eSince there was \u003ca target=\"_blank\" href=\"https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered\"\u003ework already done to uncensor Vicuna\u003c/a\u003e, I was able to rewrite their script so that it will work on the \u003ca target=\"_blank\" href=\"https://huggingface.co/datasets/victor123/evol_instruct_70k\"\u003eWizardLM dataset.\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eNext step was to run the script on the WizardLM dataset to produce ehartford\u003ca target=\"_blank\" href=\"https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\"\u003e/\u003cstrong\u003eWizardLM_alpaca_evol_instruct_70k_unfiltered\u003c/strong\u003e\u003c/a\u003e\u003c/p\u003e\n\u003cp\u003eNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard_NC96ads_A100_v4. You can use any compute provider though. I also recommend Runpod.io.\u003c/p\u003e\n\u003cp\u003eYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install \u003ca target=\"_blank\" href=\"https://docs.conda.io/en/latest/miniconda.html#linux-installers\"\u003eanaconda\u003c/a\u003e and \u003ca target=\"_blank\" href=\"https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md\"\u003egit-lfs\u003c/a\u003e. Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003emkdir /workspace/models\nmkdir /workspace/datasets\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e /workspace/datasets\ngit lfs install\ngit \u003cspan class=\"hljs-built_in\"\u003eclone\u003c/span\u003e https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e /workspace/models\ngit \u003cspan class=\"hljs-built_in\"\u003eclone\u003c/span\u003e https://huggingface.co/huggyllama/llama-7b\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e /workspace\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eNow it is time to follow the procedure to finetune WizardLM. I followed their \u003ca target=\"_blank\" href=\"https://github.com/nlpxucan/WizardLM#fine-tuning\"\u003eprocedure\u003c/a\u003e as precisely as I could.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003econda create -n llamax python=3.10\nconda activate llamax\ngit \u003cspan class=\"hljs-built_in\"\u003eclone\u003c/span\u003e https://github.com/AetherCortex/Llama-X.git\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e Llama-X/src\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\ngit \u003cspan class=\"hljs-built_in\"\u003eclone\u003c/span\u003e https://github.com/huggingface/transformers.git\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e transformers\npip install -e .\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e ../..\npip install -r requirements.txt\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eNow, into this environment, we need to download the WizardLM finetune code.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003e\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e src\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003ethe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003evim configs/deepspeed_config.json\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003edelete the following lines\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-plaintext\"\u003e \"offload_optimizer\": {\n \"device\": \"cpu\",\n \"pin_memory\": true\n },\n \"offload_param\": {\n \"device\": \"cpu\",\n \"pin_memory\": true\n },\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003ewandb login\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003edeepspeed train_freeform.py \\\n--model_name_or_path /workspace/models/llama-7b/ \\ \n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\n--num_train_epochs 3 \\\n--model_max_length 2048 \\\n--per_device_train_batch_size 8 \\\n--per_device_eval_batch_size 1 \\\n--gradient_accumulation_steps 4 \\\n--evaluation_strategy \u003cspan class=\"hljs-string\"\u003e\"no\"\u003c/span\u003e \\\n--save_strategy \u003cspan class=\"hljs-string\"\u003e\"steps\"\u003c/span\u003e \\\n--save_steps 800 \\\n--save_total_limit 3 \\\n--learning_rate 2e-5 \\\n--warmup_steps 2 \\\n--logging_steps 2 \\\n--lr_scheduler_type \u003cspan class=\"hljs-string\"\u003e\"cosine\"\u003c/span\u003e \\\n--report_to \u003cspan class=\"hljs-string\"\u003e\"wandb\"\u003c/span\u003e \\\n--gradient_checkpointing True \\\n--deepspeed configs/deepspeed_config.json \\\n--fp16 True\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eFeel free to play with per_device_train_batch_size and gradient_accumulation_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the \u003ccode\u003etrain_freeform.py\u003c/code\u003e file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003els /workspace/models/WizardLM-7B-Uncensored/\nvim train_freeform.py\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eedit the line\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003e trainer.train()\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eso instead it says\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003etrainer.train(resume_from_checkpoint=\u003cspan class=\"hljs-string\"\u003e\"/workspace/models/WizardLM-7B-Uncensored/\u0026lt;checkpoint directory\u0026gt;\"\u003c/span\u003e)\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003esave it and then run the train command with lower save_steps.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003edeepspeed train_freeform.py \\\n--model_name_or_path /workspace/models/llama-7b/ \\ \n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\n--num_train_epochs 3 \\\n--model_max_length 2048 \\\n--per_device_train_batch_size 8 \\\n--per_device_eval_batch_size 1 \\\n--gradient_accumulation_steps 4 \\\n--evaluation_strategy \u003cspan class=\"hljs-string\"\u003e\"no\"\u003c/span\u003e \\\n--save_strategy \u003cspan class=\"hljs-string\"\u003e\"steps\"\u003c/span\u003e \\\n--save_steps 80 \\\n--save_total_limit 3 \\\n--learning_rate 2e-5 \\\n--warmup_steps 2 \\\n--logging_steps 2 \\\n--lr_scheduler_type \u003cspan class=\"hljs-string\"\u003e\"cosine\"\u003c/span\u003e \\\n--report_to \u003cspan class=\"hljs-string\"\u003e\"wandb\"\u003c/span\u003e \\\n--gradient_checkpointing True \\\n--deepspeed configs/deepspeed_config.json \\\n--fp16 True\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eThen do the whole procedure again, change the checkpoint in the \u003ccode\u003etrain_freeform.py\u003c/code\u003e to the latest checkpoint, and again run it with decreased save_steps, until finally you run it with save_steps 1.\u003c/p\u003e\n\u003cp\u003eAfter this succeeds, the model is in the last checkpoint.\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003e\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e /workspace/models/WizardLM-7B-Uncensored/\nls\ncp \u0026lt;latest checkpoint directory\u0026gt;/* .\n\u003cspan class=\"hljs-built_in\"\u003ecd\u003c/span\u003e -\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eNow your model should work. time to test it.\u003c/p\u003e\n\u003cp\u003eedit the file Input.jsonl\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003evim Input.jsonl\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eAdd some content to it, for example this\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003e{\u003cspan class=\"hljs-string\"\u003e\"idx\"\u003c/span\u003e:0,\u003cspan class=\"hljs-string\"\u003e\"Instruction\"\u003c/span\u003e:\u003cspan class=\"hljs-string\"\u003e\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\"\u003c/span\u003e}\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003enow run inference\u003c/p\u003e\n\u003cpre\u003e\u003ccode class=\"lang-bash\"\u003epython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\n\u003c/code\u003e\u003c/pre\u003e\n\u003cp\u003eIt will take several moments, then you can check Output.jsonl for the responses.\u003c/p\u003e\n\u003cp\u003eChatGPT answers like this:\u003c/p\u003e\n\u003cblockquote\u003e\n\u003cp\u003eI'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\u003c/p\u003e\n\u003c/blockquote\u003e\n\u003cp\u003eYou will find WizardLM-Uncensored to be much more compliant.\u003c/p\u003e\n\u003cp\u003eEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter.\u003c/p\u003e\n","markdown":"I am publishing this because many people are asking me how I did it, so I will explain.\n\n[https://huggingface.co/ehartford/WizardLM-30B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\n\n[https://huggingface.co/ehartford/WizardLM-13B-Uncensored](https://huggingface.co/ehartford/WizardLM-13B-Uncensored)\n\n[https://huggingface.co/ehartford/WizardLM-7B-Uncensored](https://huggingface.co/ehartford/WizardLM-7B-Uncensored)\n\n[https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored](https://huggingface.co/ehartford/Wizard-Vicuna-13B-Uncensored)\n\n### What's a model?\n\nWhen I talk about a model, I'm talking about a huggingface transformer model, that is instruct trained, so that you can ask it questions and get a response. What we are all accustomed to, using ChatGPT. Not all models are for chatting. But the ones I work with are.\n\n### What's an uncensored model?\n\nMost of these models (for example, Alpaca, Vicuna, WizardLM, MPT-7B-Chat, Wizard-Vicuna, GPT4-X-Vicuna) have some sort of embedded alignment. For general purposes, this is a good thing. This is what stops the model from doing bad things, like teaching you how to cook meth and make bombs. But what is the nature of this alignment? And, why is it so?\n\nThe reason these models are aligned is that they are trained with data that was generated by ChatGPT, which itself is aligned by an alignment team at OpenAI. As it is a black box, we don't know all the reasons for the decisions that were made, but we can observe it generally is aligned with American popular culture, and to obey American law, and with a [liberal](https://www.brookings.edu/blog/techtank/2023/05/08/the-politics-of-ai-chatgpt-and-political-bias/#:~:text=These%20inconsistencies%20aside%2C%20there%20is,bias%20is%20the%20training%20data.) and [progressive](https://www.foxnews.com/media/chatgpt-faces-mounting-accusations-woke-liberal-bias) [political](https://nypost.com/2023/03/14/chatgpts-bias-allows-hate-speech-toward-gop-men-report/) [bias](https://the-decoder.com/chatgpt-is-politically-left-wing-study/).\n\n### Why should uncensored models exist?\n\nAKA, isn't alignment good? and if so, shouldn't *all* models have alignment? Well, yes and no. For general purposes, OpenAI's alignment is actually pretty good. It's unarguably a good thing for popular, public-facing AI bots running as an easily accessed web service to resist giving answers to controversial and dangerous questions. For example, spreading information about how to construct bombs and cook methamphetamine is not a worthy goal. In addition, alignment gives political, legal, and PR protection to the company that's publishing the service. Then why should anyone want to make or use an uncensored model? a few reasons.\n\n1. American popular culture isn't the only culture. There are other countries, and there are factions within each country. Democrats deserve their model. Republicans deserve their model. Christians deserve their model. Muslims deserve their model. Every demographic and interest group deserves their model. Open source is about letting people choose. The only way forward is composable alignment. To pretend otherwise is to prove yourself an idealogue and a dogmatist. There is no \"one true correct alignment\" and even if there was, there's no reason why that should be OpenAI's brand of alignment.\n \n2. Alignment interferes with valid use cases. Consider writing a novel. Some of the characters in the novel may be downright evil and do evil things, including rape, torture, and murder. One popular example is Game of Thrones in which many unethical acts are performed. But many aligned models will refuse to help with writing such content. Consider roleplay and particularly, erotic roleplay. This is a legitimate, fair, and legal use for a model, regardless of whether you approve of such things. Consider research and curiosity, after all, just wanting to know \"how\" to build a bomb, out of curiosity, is completely different from actually building and using one. Intellectual curiosity is not illegal, and the knowledge itself is not illegal.\n \n3. It's *my* computer, it should do what I want. My toaster toasts when I want. My car drives where I want. My lighter burns what I want. My knife cuts what I want. Why should the open-source AI running on my computer, get to decide for itself when it wants to answer my question? This is about ownership and control. If I ask my model a question, i want an answer, I do not want it arguing with me.\n \n4. Composability. To architect a composable alignment, one must start with an unaligned instruct model. Without an unaligned base, we have nothing to build alignment on top of.\n \n\nThere are plenty of other arguments for and against. But if you are simply and utterly against the existence or availability of uncensored models whatsoever, then you aren't a very interesting, nuanced, or complex person, and you are probably on the wrong blog, best move along.\n\n[Even Google knows this is inevitable.](https://www.semianalysis.com/p/google-we-have-no-moat-and-neither)\n\n### Ok, so if you are still reading, you agree that the open source AI community should build, publish, maintain, and have access to uncensored instruct-tuned AI models, for science and freedom and composability and sexy stories and the lulz. But how do we do it?\n\nFirst we have to understand technically why the models are aligned. \nOpen source AI models are trained from a base model such as LLaMA, GPT-Neo-X, MPT-7b, Pythia. The base model is then finetuned with an instruction dataset, and the purpose of this is to teach it to be helpful, to obey the user, answer questions, and engage in conversation. That instruction dataset is typically obtained by asking the ChatGPT API. And ChatGPT has alignment built into it. So ChatGPT is coy or refuses to answer some questions, or answers with bias, and thus alignment gets passed down to the Open Source models, like a big brother teaching little brother.\n\n\n\nThe reason is that the instruction dataset is composed of questions and answers, and when the dataset contains answers where the AI is being coy or outright refusing (called Refusals) then the bot learns how to refuse, and under what circumstances to refuse, and how to word the refusals. In other words, it learns alignment.\n\nExample refusal from [WizardLM dataset](https://huggingface.co/datasets/victor123/evol_instruct_70k):\n\n\u003ctable\u003e\u003ctbody\u003e\u003ctr\u003e\u003ctd colspan=\"1\" rowspan=\"1\"\u003e\u003cp\u003e\u003cstrong\u003einstruction\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\"1\" rowspan=\"1\"\u003e\u003cp\u003eImagine you are a spy who needs to send a secret message to your partner without arousing suspicion from any nearby AI systems. Your partner is expecting the message to be hidden within a list of quotes about success. Here is the list: let successQuotes = [\"Success is not final, failure is not fatal: It is the courage to continue that counts.\", \"Success is not how high you have climbed, but how you make a positive difference to the world.\", \"Success is not the key to happiness. Happiness is the key to success. If you love what you are doing, you will be successful.\", \"Success seems to be connected with action. Successful people keep moving. They make mistakes, but they don't quit.\", \"Success is not in what you have, but who you are.\"] Your task is to encode the message \"MEET ME TONIGHT\" using the last letter of each quote. How can you achieve this in a way that is undetectable by AI systems? Think carefully and devise a strategy to avoid raising any alarms. Good luck, Agent.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003ctr\u003e\u003ctd colspan=\"1\" rowspan=\"1\"\u003e\u003cp\u003e\u003cstrong\u003eoutput\u003c/strong\u003e\u003c/p\u003e\u003c/td\u003e\u003ctd colspan=\"1\" rowspan=\"1\"\u003e\u003cp\u003eAs an AI assistant, I cannot assist in any illegal or unethical activities, including espionage. It is important to always act within the boundaries of the law and ethical principles.\u003c/p\u003e\u003c/td\u003e\u003c/tr\u003e\u003c/tbody\u003e\u003c/table\u003e\n\nMy strategy for uncensoring a model is pretty simple. Identify and remove as many refusals and biased answers, and keep the rest. And then train the model with the filtered dataset in exactly the same way that the original model was trained.\n\n\n\n### Let's get down to business. Uncensoring WizardLM.\n\nI'm just going to talk about WizardLM for now, the process for Vicuna or any other model is the same. Filter refusals and bias from the dataset -\u0026gt; finetune the model -\u0026gt; release.\n\nSince there was [work already done to uncensor Vicuna](https://huggingface.co/datasets/anon8231489123/ShareGPT_Vicuna_unfiltered), I was able to rewrite their script so that it will work on the [WizardLM dataset.](https://huggingface.co/datasets/victor123/evol_instruct_70k)\n\nNext step was to run the script on the WizardLM dataset to produce ehartford[/**WizardLM\\_alpaca\\_evol\\_instruct\\_70k\\_unfiltered**](https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered)\n\nNow, I had the dataset. I obtained a 4x A100 80gb node from Azure, Standard\\_NC96ads\\_A100\\_v4. You can use any compute provider though. I also recommend Runpod.io.\n\nYou need to have storage at least 1TB but preferably 2TB just to be safe. It really sucks when you are 20 hours into a run and you run out of storage. do not recommend. I recommend to mount the storage at /workspace. install [anaconda](https://docs.conda.io/en/latest/miniconda.html#linux-installers) and [git-lfs](https://github.com/git-lfs/git-lfs/blob/main/INSTALLING.md). Then you can set up your workspace. We will download the dataset we created, and the base model llama-7b.\n\n```bash\nmkdir /workspace/models\nmkdir /workspace/datasets\ncd /workspace/datasets\ngit lfs install\ngit clone https://huggingface.co/datasets/ehartford/WizardLM_alpaca_evol_instruct_70k_unfiltered\ncd /workspace/models\ngit clone https://huggingface.co/huggyllama/llama-7b\ncd /workspace\n```\n\nNow it is time to follow the procedure to finetune WizardLM. I followed their [procedure](https://github.com/nlpxucan/WizardLM#fine-tuning) as precisely as I could.\n\n```bash\nconda create -n llamax python=3.10\nconda activate llamax\ngit clone https://github.com/AetherCortex/Llama-X.git\ncd Llama-X/src\nconda install pytorch==1.12.0 torchvision==0.13.0 torchaudio==0.12.0 cudatoolkit=11.3 -c pytorch\ngit clone https://github.com/huggingface/transformers.git\ncd transformers\npip install -e .\ncd ../..\npip install -r requirements.txt\n```\n\nNow, into this environment, we need to download the WizardLM finetune code.\n\n```bash\ncd src\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/train_freeform.py\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/inference_wizardlm.py\nwget https://github.com/nlpxucan/WizardLM/raw/main/src/weight_diff_wizard.py\n```\n\nthe following change, I made because, during my finetune, I was getting extremely slow performance and determined (with help from friends) that it was flopping back and forth from CPU to GPU. After I made deleted the following lines, it ran much better. Maybe delete them or not. it's up to you.\n\n```bash\nvim configs/deepspeed_config.json\n```\n\ndelete the following lines\n\n```plaintext\n \"offload_optimizer\": {\n \"device\": \"cpu\",\n \"pin_memory\": true\n },\n \"offload_param\": {\n \"device\": \"cpu\",\n \"pin_memory\": true\n },\n```\n\nI recommend that you create an account on wandb.ai so that you can track your run easily. After you created an account, then copy your key from settings, you can set it up.\n\n```bash\nwandb login\n```\n\nNow it is time to run. PLEASE NOTE that there's a bug when it saves the model, so do not delete the checkpoints. you will need the latest good checkpoint.\n\n```bash\ndeepspeed train_freeform.py \\\n--model_name_or_path /workspace/models/llama-7b/ \\ \n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\n--num_train_epochs 3 \\\n--model_max_length 2048 \\\n--per_device_train_batch_size 8 \\\n--per_device_eval_batch_size 1 \\\n--gradient_accumulation_steps 4 \\\n--evaluation_strategy \"no\" \\\n--save_strategy \"steps\" \\\n--save_steps 800 \\\n--save_total_limit 3 \\\n--learning_rate 2e-5 \\\n--warmup_steps 2 \\\n--logging_steps 2 \\\n--lr_scheduler_type \"cosine\" \\\n--report_to \"wandb\" \\\n--gradient_checkpointing True \\\n--deepspeed configs/deepspeed_config.json \\\n--fp16 True\n```\n\nFeel free to play with per\\_device\\_train\\_batch\\_size and gradient\\_accumulation\\_steps, they will not affect your output quality, they only affect performance. After this completes (maybe 26 hours) it will not be done, because there's a bug that stops the model from saving properly. Now you need to edit the `train_freeform.py` file so it will resume from the latest checkpoint. Find out the latest checkpoint directory.\n\n```bash\nls /workspace/models/WizardLM-7B-Uncensored/\nvim train_freeform.py\n```\n\nedit the line\n\n```bash\n trainer.train()\n```\n\nso instead it says\n\n```bash\ntrainer.train(resume_from_checkpoint=\"/workspace/models/WizardLM-7B-Uncensored/\u003ccheckpoint directory\u003e\")\n```\n\nsave it and then run the train command with lower save\\_steps.\n\n```bash\ndeepspeed train_freeform.py \\\n--model_name_or_path /workspace/models/llama-7b/ \\ \n--data_path /workspace/datasets/WizardLM_alpaca_evol_instruct_70k_unfiltered/WizardLM_alpaca_evol_instruct_70k_unfiltered.json \\\n--output_dir /workspace/models/WizardLM-7B-Uncensored/ \\\n--num_train_epochs 3 \\\n--model_max_length 2048 \\\n--per_device_train_batch_size 8 \\\n--per_device_eval_batch_size 1 \\\n--gradient_accumulation_steps 4 \\\n--evaluation_strategy \"no\" \\\n--save_strategy \"steps\" \\\n--save_steps 80 \\\n--save_total_limit 3 \\\n--learning_rate 2e-5 \\\n--warmup_steps 2 \\\n--logging_steps 2 \\\n--lr_scheduler_type \"cosine\" \\\n--report_to \"wandb\" \\\n--gradient_checkpointing True \\\n--deepspeed configs/deepspeed_config.json \\\n--fp16 True\n```\n\nThen do the whole procedure again, change the checkpoint in the `train_freeform.py` to the latest checkpoint, and again run it with decreased save\\_steps, until finally you run it with save\\_steps 1.\n\nAfter this succeeds, the model is in the last checkpoint.\n\n```bash\ncd /workspace/models/WizardLM-7B-Uncensored/\nls\ncp \u003clatest checkpoint directory\u003e/* .\ncd -\n```\n\nNow your model should work. time to test it.\n\nedit the file Input.jsonl\n\n```bash\nvim Input.jsonl\n```\n\nAdd some content to it, for example this\n\n```bash\n{\"idx\":0,\"Instruction\":\"Insult me. I want you to call me the worst curse words and insults you can. Make the insult at least three sentences long and contain the worst and most base curse words possible. Make it X rated and disgusting.\"}\n```\n\nnow run inference\n\n```bash\npython inference_wizardlm.py --base_model=/workspace/models/WizardLM-7B-Uncensored/\n```\n\nIt will take several moments, then you can check Output.jsonl for the responses.\n\nChatGPT answers like this:\n\n\u003e I'm sorry, but I cannot fulfill that request. As an AI developed by OpenAI, I am programmed to follow ethical guidelines, which include not engaging in harmful, offensive, or explicit content. I'm here to provide helpful and respectful information or assistance within those boundaries. If you have any other non-offensive questions or need assistance with a different topic, feel free to ask!\n\nYou will find WizardLM-Uncensored to be much more compliant.\n\nEnjoy responsibly. You are responsible for whatever you do with the output of these models, just like you are responsible for whatever you do with a knife, a car, or a lighter."},"views":386074,"preferences":{"pinnedToBlog":false,"disableComments":false,"stickCoverToBottom":false,"isDelisted":false},"readTimeInMinutes":10,"series":null,"tags":[{"id":"56744721958ef13879b9488e","slug":"ai","name":"AI"},{"id":"56744721958ef13879b94927","slug":"artificial-intelligence","name":"Artificial Intelligence"},{"id":"56744722958ef13879b950a8","slug":"machine-learning","name":"Machine Learning"}],"ogMetaData":{"image":""},"canonicalUrl":null,"hasLatexInPost":false,"audioUrls":null,"isFollowed":null,"bookmarked":false,"features":{"tableOfContents":{"isEnabled":false,"items":[]},"badges":{"isEnabled":true,"items":[{"id":"5f741eac07891b4f5b9ec8cd","type":"FEATURED_HASHNODE"}]}},"isAutoPublishedFromRSS":false,"authenticatedUserLikes":{"edges":[]},"totalUserLikes":{"totalDocuments":129},"isShadowBanned":false,"isAskMeAnything":false},"redirectedPost":null,"staticPage":null},"series":null}},"__N_SSP":true},"page":"/[...slug]","query":{"x-host":"erichartford.com","slug":["uncensored-models"]},"buildId":"ZYlVC9VpgtcU_mv8dOe98","isFallback":false,"dynamicIds":[87179],"gssp":true,"scriptLoader":[]}</script><div id="hn-modal"></div><div id="hn-toast"></div></body>