ChatGLM3

最近 ChatGLM3 火出圈了,听说非常不错,就尝试用常用的云平台(趋动云)尝试一下。

首先创建一个新项目

ChatGLM3_第1张图片

 镜像选择公开的镜像

ChatGLM3_第2张图片

 模型也是

ChatGLM3_第3张图片

 然后弹窗选择“暂不上传”

ChatGLM3_第4张图片

点击“开发”的“初始化开发环境实例”

 选择B1.large卡,直接开始(B1.medium其实也可以或者更大的也可以,毕要看你的输入,这里选择适中的卡)

ChatGLM3_第5张图片

ChatGLM3_第6张图片

 点击“New Launcher”后选择“Python 3”的Notebook新建文件,并命名为“chatglm3”

采用官网的代码调用来看是否可以正常运行THUDM/ChatGLM3: ChatGLM3 series: Open Bilingual Chat LLMs | 开源双语对话语言模型 (github.com)icon-default.png?t=N7T8https://github.com/THUDM/ChatGLM3

ChatGLM3_第7张图片

代码如下(不过要改下模型文件路径):(最后两行最好重新分为一个cell,避免再一次加载模型)

from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("../pretrain", trust_remote_code=True)
model = AutoModel.from_pretrained("../pretrain", trust_remote_code=True, device='cuda')
model = model.eval()
response, history = model.chat(tokenizer, "你好", history=[])
print(response)

然后直接按“Shift+Enter”开始运行

ChatGLM3_第8张图片

模型加载要等待一段时间

 ChatGLM3_第9张图片

我们试试复杂的 prompt 看能否应对

另外,关于复杂 prompt 的构成可以参见我写的知乎

高阶 Prompt —— API 细节及重要技巧 - 知乎 (zhihu.com)icon-default.png?t=N7T8https://zhuanlan.zhihu.com/p/663152784

prompt = """
You are an expert in Toefl writing. I will give you 3 examples (in  XML tags) in different topics for reference, and then follow the form (in 
XML tags) to give a satisfied answer! Topic: Why go to university? Answer: University is no longer a fresh word to people nowadays. Since the beginning of this century, more and more youngsters choose to enter university after they have completed the study in high schools rather than to join the army or become an apprentice. Therefore, it is kind of interesting to find out the reason behind. First of all, students can only learn fundamental knowledge during high school while they are able to focus on their own interested majors in universities. This period is the key to knowledge accumulation, which will contribute a lot to the future of an individual. Moreover, university is no doubt the symbol of high education. It offers more than pure knowledge. A degree from a university gives people certain identity that makes them stand out among their competitors. It can be seen from the fact that most international companies will only hire those who have at least a Bachelor's degree. Sincere dreams might also be the reason for university or college. For instance, in the 60s and 70s, people in China experienced hard times. Many of them had to give up advanced education and take up the burdens of life at their early age. Now, as they became parents or even grandparents, their dream for university education had no doubt realized by their younger family members. Those young people, as reported, often study very hard in order to fulfill the expectations of two generations. There is no doubt that university can be the turning point of one's future, because higher education will provide people with not only knowledge prepared for their careers, but also the fulfillment of their life goals. Meanwhile, the society has improved its strength to sponsor higher education. Compared with the past, people now attend universities also because they are able to secure various scholarships and supports from different channels. A very good example is that many Chinese students are now studying in the U. S. Their incentive for application should be attributed to not only to their own performance but also the comprehensive education frameworks in the U. S. Broadly speaking, people who study in universities have their hopes: to fulfill themselves. At the same time, our society generously provides such an environment for people to achieve such goals. Therefore, when we see more and more fresh smiles on the campus of universities, let us just wish them a promising future. Topic: Are parents best teachers? Answer: Parents are the most committed, the most influential, and almost the best teachers any child can have. The amount of time a child interacts with parents makes them the most influential force in a child's life. The child gets to learn the most basics of things like walking, speaking and interacting with others. It is under the protections of parents that a child learns to behave in society and to comfort him or herself. Although parents are the most influential teachers in their children's life, they may not be regarded as the best teachers. Parents generally provide a biased view of the world; they always favor their child, and thus they cannot provide a complete panoramic view of the society. Also parents may set a bad example for their child by abusing and fighting amongst themselves. Psychologists and recent crime charts have proved that young outlaws generally come from disrespectful families, and have grown up in extreme environments. A child interacts with many kinds of teachers at schools and colleges. Although these teachers, being professionals, have limited time to devote to a child, they provide a complete and diverse view to their students. They provide unbiased guidance to a child. During the years of adolescence, children tend to be aggressive and non-conforming to others' views. So parents need to act like friends rather than teachers. Eventually, it is the parents who provide an environment for a child to develop and mature, and thus have the capacity to be the best teachers to their child. What is important is to provide an unbiased view to their child, to motivate independent thinking and actuate timely maturation. Topic: Has the easiness of cooking improved life? Answer: People work hard to fulfill their principal necessities, and food is the one thing that is really important to their survival. Although sometimes belied by other things that seem important, food is the core objective that drives all people to work. But the outcome of the efforts of these people is not a direct supply of food; rather it is in the form of money. Thus these people use the money they obtain to prepare their food. In old days, preparing food was cumbersome and timeconsuming work for those who do it solely for eating purposes. This kind of preparing food in due tie could not comply with the kind of life people lead today. The use of technological advancement makes preparing food practical even for the clumsiest person. This helps a great deal for those who work against time to make their living. It also avoids the waste of considerable amount of money from hiring a cook. The development in the preparation of food is highly effective for those people who have no know how of it. A person who does not know how to prepare his/her own food would go to a restaurant or some other place where food is served everyday. But with the advanced food preservation technology, now he is free, completely independent of restaurants and other places. He can prepare his own food and enjoy the feeling of "home, sweet home". For people at work, life has just become easy for them. They will not have to worry all day long about what they are going to prepare for their supper. They can fully concentrate on their jobs, and work with a mind full of peace. In general this new way of preparing food has helped those who are concerned about their daily meals -- almost everyone. Not only that, it would enlighten those who are frustrated with their jobs just because of the worry of that tiresome work -- preparing food. Topic: Books and experience Answer: """

ChatGLM3_第10张图片

可以看到结果还是相当的不错的!

我也试过 prompt 12个例子的,输出结果真的很令人满意!!!不过由于数据的私有性所以在此处不再展示!!!

ChatGLM3 的出现真的让我看到了小模型的希望,效果如此的好,可以考虑做微调等等下一步了!!! 

你可能感兴趣的:(云平台部署,LLMs,语言模型)