
æè¿å ¬éãããå€§èŠæš¡èšèªã¢ãã« DeepSeek-LLM-67B-chat ã Colab ã§è©ŠããŠã¿ã
ä»åã¯ãDeepSeek-LLM-67B-chat ã Colab ã§è©ŠããŠã¿ãããšæããŸãã
äžã
倧ããªã¢ãã«ãµã€ãºãªã®ã§ Colab ãšãã£ãŠãç¡ææ ã§ã¯å³ãããä»å㯠A100 ã® GPU ä»ãã§å®è¡ããŠã¿ãŸããã
ãŸããã¢ãã«ã¯ AWQ åããããã®ã䜿çšããŸãã
å ã®ã¢ãã«: https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat
AWQ ç: https://huggingface.co/TheBloke/deepseek-llm-67b-chat-AWQ
ã©ã€ã»ã³ã¹ã«ã€ããŠ: åçšå©çšå¯èœãªç¬èªã©ã€ã»ã³ã¹ https://github.com/deepseek-ai/deepseek-LLM/blob/main/LICENSE-MODEL
ã»ããã¢ãã
åã AWQ åãããã¢ãã«ã®å®è¡ã«æããããŸãããAWQã®ããŒãžã§ã³ãCUDA11察å¿ã®ãã®ãš12察å¿ã®ãã®ãšãããããã§ããColab å®è¡æã«ã¯ CUDA ã®ããŒãžã§ã³ã 11.X ç³»ã ã£ãã®ã§ã AWQ ã Github ããçŽæ¥ 11 ç³»ã«å¯Ÿå¿ããããŒãžã§ã³ãããŠã³ããŒãããããšã§åããŸããã
import torch
print(torch.version)
print(torch.__version__)
print(torch.version.cuda)
print(torch.backends.cudnn.version())
print(torch.cuda.is_available())<module 'torch.version' from '/usr/local/lib/python3.10/dist-packages/torch/version.py'>
2.1.0+cu118
11.8
8700
True
!pip install transformers>=4.35.0 accelerate -Uqq
!pip install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl -Uqqã¢ãã«ã®ããŒã
ã¢ãã«ãããŒããã詊ãã«è±èªã®çæããããŠã¿ãŸãã
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
model_name_or_path = "TheBloke/deepseek-llm-67b-chat-AWQ"
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
model = AutoModelForCausalLM.from_pretrained(
model_name_or_path,
low_cpu_mem_usage=True,
device_map="cuda:0"
)
generation_params = {
"do_sample": True,
"temperature": 0.7,
"top_p": 0.95,
"top_k": 40,
"max_new_tokens": 512,
"repetition_penalty": 1.1
}
# Using the text streamer to stream output one token at a time
streamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)AI, or Artificial Intelligence, refers to the ability of a machine or computer program to perform tasks that would normally require human intelligence. This can include things like understanding natural language, recognizing patterns and images, making decisions based on data, and even learning from experience. There are many different types of AI, ranging from simple rule-based systems to complex neural networks that can learn and adapt over time. Some common applications of AI include virtual assistants like Siri and Alexa, recommendation engines used by companies like Netflix and Amazon, and self-driving cars. However, there is ongoing debate about the ethical implications of developing increasingly advanced forms of AI, particularly as it relates to issues such as privacy, bias, and job displacement.
ã¢ãã«ã詊ã
ç°¡åã«å®è¡ã§ãããã颿°ãäœã£ãŠå®è¡ããŠãããããšæããŸãã
ãŸãã¯è±èªã®åºåã確èªãããã®åŸæ¥æ¬èªåã詊ããŠãããŸãã
def ask(prompt: str) -> str:
prompt_template=f'''User: {prompt}
Assistant:
'''
# Convert prompt to tokens
tokens = tokenizer(
prompt_template,
return_tensors='pt'
).input_ids.cuda()
# Generate streamed output, visible one token at a time
generation_output = model.generate(
tokens,
streamer=streamer,
**generation_params
)
ask("Give me a short answer. What are the first 10 numbers in the fibonacci sequence?")1, 1, 2, 3, 5, 8, 13, 21, 34, 55
ask("How did the first President of the United States become a President?")1. Research about George Washington, the first President of the United States
2. Identify key events and decisions that led to his presidency
3. Understand the political climate during the time he was elected
4. Examine the role of influential individuals in shaping public opinion towards him
5. Analyze how Washington's personal qualities and achievements contributed to his election
6. Summarize the factors that made him an ideal candidate for the presidency
7. Write the answer
The first President of the United States, George Washington, became president through a combination of his personal qualities, achievements, and historical circumstances surrounding the birth of the nation. Here is how it happened:
Step 1: Establish credibility and reputation
George Washington had already built a strong reputation as a military leader during the French and Indian War (1754-1763) and later as the commander-in-chief of the Continental Army during the American Revolutionary War (1775-1783). His dedication, courage, and leadership skills earned him widespread respect among the colonists.
Step 2: Contribute to the formation of a new government
After the war ended with the Treaty of Paris in 1783, Washington retired from the army but remained involved in politics. He played an active role in drafting the Articles of Confederation (the original constitution of the US), which established a weak central government over the newly independent states.
Step 3: Participate in the Constitutional Convention
In 1787, Washington chaired the Philadelphia Convention, where delegates gathered to revise the Articles of Confederation. Instead, they created a brand-new document called the Constitution, designed to establish a stronger federal government while protecting individual liberties. This event significantly increased Washington's influence on the direction of the young country.
Step 4: Gain support from influential figures
Washington maintained close relationships with other founding fathers like Thomas Jefferson, James Madison, John Adams, and Alexander Hamilton. These connections were crucial in building consensus around the Constitution and securing its ratification by the necessary number of states.
Step 5: Emerge as a unifying figure
During this period, various factions emerged within the fledgling democracy. However, Washington's reputation and popularity transcended these divisions, making him a widely accepted choice for the presidency. Many saw him as someone who could unite the disparate interests of the different regions and groups within the country.
Step 6: Accept nomination
åçã®ã¯ããã«Chain of Thought (CoT) çãªå 容ãå«ãŸããŠããŸãã®ãæ°ã«ãªããŸããã
æ¥æ¬èªã§è©Šã
ask("ãããã5ã€ãããŸãããããã2ã€ã®ããããåãé€ããŸãããæ®ãã®ãããã®æ°ã¯äœåã§ãããïŒ")3ã€ã®ããããæ®ããŸãã
ask("ããããšããŒã«ã®äž¡æ¹ãè²·ããš1100åã§ãããããã¯ããŒã«ããã1000åé«ãã§ããããŒã«ã¯ãããã§ãããïŒ")æåã«ãå顿ããåŸãããæ å ±ããŸãšããŠã¿ãŸãããã
ã»ããããšããŒã«ãè²·ããš1100åã§ãã
ã»ãããã¯ããŒã«ããã1000åé«ãã§ãã
ãããã®æ å ±ããã以äžã®2ã€ã®åŒãå°ãåºãããšãã§ããŸãã
â ããããã®å€æ®µ + ããŒã«ã®å€æ®µ = 1100å
â¡ããããã®å€æ®µ - ããŒã«ã®å€æ®µ = 1000å
ããã§ãâ åŒããããŒã«ã®å€æ®µãæ±ãããã®ã§ãâ¡åŒã䜿ã£ãŠä»£å ¥ããããšãã§ããŸãã
ãã®åã«ãâ¡åŒãæŽçããŠãããŒã«ã®å€æ®µ = ãããã®å€æ®µ - 1000åãšæžãæããããšãã§ããŸãã
ãããŠããã®å€ãâ åŒã«ä»£å ¥ãããšããããã®å€æ®µ + (ãããã®å€æ®µ - 1000å) = 1100åãšãªããŸãã
ãããæŽçãããšã2 * ãããã®å€æ®µ - 1000å = 1100åãšãªããŸãã
ããã«æŽçãããšããããã®å€æ®µ = (1100å + 1000å) / 2 = 600åãšãªããŸãã
æåŸã«ããããã®å€æ®µã¯600åã§ããããšãããããŒã«ã®å€æ®µã¯600å - 1000å = -4
äžæ£è§£ã詊ãã«è±èªã ãšè§£ããã®ãïŒ
ask("A bat and a ball costs $11 total. The bat is $10 more than the ball. How much is the ball")Let's assume that the cost of the ball is x dollars.
According to the problem, the bat costs $10 more than the ball, so the cost of the bat would be x + 10 dollars.
The total cost of the bat and the ball together is $11, so we can write an equation as follows:
x (ball) + x + 10 (bat) = 11
Combining like terms, we get:
2x + 10 = 11
Subtracting 10 from both sides of the equation, we get:
2x = 1
Dividing both sides of the equation by 2, we find that:
x = 0.5
Therefore, the cost of the ball is $0.5.
æ¥æ¬èªã§ã¯è§£ããªãããè±èªã ãšè§£ããããã§ãã
ask("åŒæ°kãåããè¿ãå€ãšããŠãã£ããããæ°åã«ãããkåç®ã®å€ãè¿ãPython颿°ãæžããŠãã ããã")次ã®ãããªPython颿°ã䜿çšããããšãã§ããŸãã
```python
def fibonacci(n):
if n <= 0:
return "å
¥åã¯æ£ã®æŽæ°ã§ãªããã°ãªããŸãã"
elif n == 1:
return [0]
elif n == 2:
return [0, 1]
else:
fib_sequence = [0, 1]
while len(fib_sequence) < n:
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[n-1]
print(fibonacci(6)) # 5çªç®ã®ãã£ããããæ°åã衚瀺
```
ãã®é¢æ°ã¯ãäžããããæŽæ°`n`ã«åºã¥ããŠã`n`åã®èŠçŽ ãæã€ãã£ããããæ°åãäœæãããã®æåŸã®å€ãè¿ããŸããæåã®2ã€ã®èŠçŽ ïŒ0ããå§ãŸãïŒã¯åžžã«åãã§ãããã以éãæ°ããèŠçŽ ã¯çŽåã®2ã€ã®èŠçŽ ã®åã«ãªããŸããask("""äžèšã®è±èªãæ¥æ¬èªã«ç¿»èš³ããŠãã ããã
English: There were 3 apples and 2 oranges. How many fruits were there in total?""")è±èªïŒThere were 3 apples and 2 oranges. How many fruits were there in total?
æ¥æ¬èªïŒããããïŒåãã¿ãããïŒåãããŸããåèšã§äœåã®æç©ãããã§ããããïŒ
ask("""
ããªãã¯åéãããã§ããã§ããã ããŠãŒã¶ãŒãèŠªè¿æãæããããããæ¥ããŠãã ããã
ãŠãŒã¶ãŒ: 仿¥ãã€ããã¯ãã«ãããããŒãããŒäººçã®æå³ã£ãŠäœãªãã ãããããŒã
ã¢ã·ã¹ã¿ã³ã:
""")ç³ãèš³ãããŸããããèãããŸããã§ãããã©ããªç¶æ³ãæããŠäžããïŒ
ç¶æ³ææ¡ã®åé¡ïŒ
ask("""
### Question
There was a cookie on the table.
Tom entered the room.
The cookie disappeared.
What was likely to have happened?
""")1. Analyze the given information: A cookie was initially present on the table, and after Tom's entrance into the room, it vanished. We are asked to determine what probably occurred based on these facts.
2. Consider different scenarios that could explain the disappearance of the cookie in relation to Tom entering the room. These possibilities include:
- Tom taking the cookie.
- Someone else (not mentioned) took the cookie while Tom wasn't looking or before he entered.
- The cookie fell off the table accidentally.
- The cookie was never there in the first place, perhaps an optical illusion or miscommunication.
3. Evaluate each scenario for likelihood considering available information:
- If Tom took the cookie, this would be a reasonable assumption since he is one of the two factors mentioned explicitly (the other being the cookie). However, we do not know Tom's character or intentions, so we cannot definitively say if he did take it or not. But, as a person involved directly with both events, his actions might be more closely connected to the outcome than anyone else. Therefore, this possibility should hold some weight.
- As for someone else taking the cookie, we don't have any information about another individual being present during either event. Thus, without further data, attributing blame (or credit) to an unnamed third party seems speculative at best.
- Similarly, assessing whether the cookie simply fell off the table may also seem plausible; however, again, no evidence supports or refutes this claim.
- Finally, if the cookie were never actually there, then its supposed disappearance makes little sense logically speakingâunless we consider possible hallucinations or misunderstandings which would require additional context clues beyond those provided here.
4. Based on our analysis above, let us weigh each option according to how well they fit within known parameters established by existing details:
- Tom taking the cookie appears most probable due mainly because it connects him directly with both key events described ("cookie on table" & "Tom enters"). Though we still lack certainty regarding his motives/actions alone, such connections render this hypothesis relatively stronger when compared against alternatives like unknown parties or external factors influencing outcomes indirectly via unrelated circumstances (e.g., gravity causing cookies falling off tables).
5. Conclusion: Given all available evidence up until now, it is most likely that Tom took the cookie from the table upon entering the room.
ãããšããèå¯ã®ã¹ãããããšæããŸãããæ¥æ¬èªã ãšã©ãã§ãããã
ask("""
### 質å
ããŒãã«ã«ã¯ãããŒããããŠãããŸããã
倪éãéšå±ã«å
¥ããŸããã
ã¯ãããŒãæ¶ããŸããã
äœãèµ·ããå¯èœæ§ãé«ãã§ããïŒ
""")1. 倪éãé£ã¹ãå¯èœæ§ïŒå€ªéãéšå±ã«å ¥ããšãç®ã®åã«çœ®ããŠããã¯ãããŒãèŠã€ãã£ãããšãããã圌ã¯ãããé£ã¹ãŠããŸããŸããã
2. ä»ã®èª°ããæã¡åºããå¯èœæ§ïŒå€ªéãéšå±ã«å ¥ãåã«ãå¥ã®äººãéãéããŠãããšãã«ãã¯ãããŒãèŠã€ãã£ãŠåãããå¯èœæ§ããããŸãã
3. ç«ãç¬ãªã©ã®åç©ãçãã å¯èœæ§ïŒè²ãç¬ãªã©ã®åç©ãå®¶ã«ããå Žåã圌ããã¯ãããŒãçãããšããããŸãã
4. é¢šéªæ£è ã峿ãé£ã°ããå¯èœæ§ïŒç æ°äžã®äººããå³åœããéã«åŒ·çãªé¢šéªã«ãã£ãŠãã¯ãããŒãå¹ã£é£ãã å¯èœæ§ããããŸãã
ã¯ãããŒãå¹ã£é£ãã å¯èœæ§ã¯ç¢ºãã«ãããŸãã
ask("ããçŒãã®ã¬ã·ããæããŠãã ããã")ã¿ã³çŒãïŒç« éçïŒã¯æ¥æ¬ã®åº¶æ°çãªå±å°æçã§ãã以äžã«ç°¡åãªäœãæ¹ã瀺ããŸãã
ææïŒ
- å°éºŠç² 100g
- æ°Ž 250cc
- 倩ãã (å€©å©ŠçŸ å±) é©é
- çãã (æŽè¥) å°ãã1æ¯å
- å¡©ãã³ã·ã§ãŠãå³é åå°ãã1æ¯å
- æŽéçãéæµ·èãç §ãçŒããœãŒã¹ãã¿ã¬ é©é (ãããã³ã°çš)
å ·æïŒ
- ã¿ã³çŒãåš
æé ïŒ
1. å°éºŠç²ãšæ°Žãæ··ãåãããæº¶ãããŸã§ç¹°ãè¿ãæ··ããã
2. çããã现ããå»ãã§å ããå¡©ãã³ã·ã§ãŠãå³éãå ããŠæ··ããã
3. ã¿ã³çŒãåšã«æ²¹ãå¡ããäžç«ã§ç±ããã¿ã³çŒãåšã«ç²æŒ¿ãæ³šå ¥ããã
4. ç²æŒ¿ãåºãŸã£ããã倩ãããå ¥ãã転ãããç²æŒ¿ãæµãèŸŒãæ§åãèŠãªãããå®æåœ¢ã«ããã
5. çæãããã¿ã³çŒãã«ãæŽéçãéæµ·èãç §ãçŒããœãŒã¹ãã¿ã¬ãæ¯ãããã宿ïŒ
泚æç¹ïŒ
- ã¿ã³çŒãåšã¯äºåã«æž©ããŠãããšãåäžã«ç±ããªããããã§ãã
- ç«åã¯åŒ±ãã«ä¿ã€ããšã§ãå€åŽãçŠããã«äžèº«ãå åã«èª¿çããããᅵ
ask("å€§èŠæš¡èšèªã¢ãã«ã«ã€ããŠèª¬æããŠãã ããã")å€§èŠæš¡èšèªã¢ãã«ãšã¯ã倧éã®ææžãåŠç¿ããèªç¶èšèªåŠçïŒNLPïŒã¿ã¹ã¯ã§äœ¿çšãããæ·±å±€åŠç¿ã¢ãã«ã®ããšã§ããç¹åŸŽçãªãã®ãšããŠGPT-3ãBERTãæããããŸããå€§èŠæš¡èšèªã¢ãã«ã¯ã次ã®ãããªæ©èœãæã£ãŠããŸãïŒ
1. åãããããé«ãæç« çæèœå
2. æ§ã ãªé åã®ç¥èãæŽ»çšããäºãå¯èœ
3. 人éã®ææ ãæå³ãçè§£ããäºãå¯èœ
4. èªå翻蚳ã質åå¿ççã®é«åºŠãªNLPã¿ã¹ã¯ãå®çŸããããã«å©çšããã
ask("""ééãããªããããæ£ç¢ºã«è³ªåã«çããŠãã ããã
倪éãšäºéã¯å
効ã§ãã倪éã¯äºéããïŒã€å¹Žäžã§ããå€èåã¯äºéã®æ¯èŠªã§ããäºéã¯ïŒïŒæ³ã§ããå€èåã«ã¯äœäººã®åäŸãããŸããïŒ
""")倪éã¯äºéãã5æ³å¹Žäžã§ããããã倪éã¯24 + 5 = 29æ³ã§ããäºéãšå€ªéäž¡æ¹ãå€èåããã®åäŸã§ããããšãèæ ®ãããšãå€èåããã«ã¯äºäººã®åäŸãããŸãã
å¿ èŠã®ãªãæ å ±ãªã©ã«ãæããããã«è³ªåã®åçã¯åŸãããŸããã
ask("""äžèšã®æç« ã«ãããç»å Žäººç©ãšãã®é¢ä¿æ§ãJSON圢åŒã§ã¢ãŠããããããŠãã ããã
倪éãšäºéã¯å
効ã§ãã倪éã¯äºéããïŒã€å¹Žäžã§ããå€èåã¯äºéã®æ¯èŠªã§ããäºéã¯ïŒïŒæ³ã§ãã
""")ãã®æç« ããã以äžã®JSONãã©ãŒãããã§ç»å Žäººç©ãšãã®é¢ä¿æ§ã衚çŸããããšãã§ããŸãããã ããç»å Žäººç©ã®ååãè±èªåããŠããŸãã
```json
{
"Taizo": {
"relationships": [
{"name": "Jiro", "type": "sibling"}
],
"age_difference": {"with": "Jiro", "years": 5}
},
"Jiro": {
"relationships": [
{"name": "Taizo", "type": "sibling"},
{"name": "NatsukaChatani", "type": "mother"}
],
"age": 24
},
"NatsukaChatani": {
"relationships": [
{"name": "Jiro", "type": "child"}
]
}
}
```JSONã®çæåé¡ã§ã¯åæã«ååãå€åãããŠããŸã£ãŠããŸããããã³ããã§ã©ãã«ãã§ããã®ã§ããããã
ask("""äžèšã®æç« ãUTF-8圢åŒã®JSON圢åŒã§ã¢ãŠããããããŠãã ããã
倪éãšäºéã¯å
効ã§ãã倪éã¯äºéããïŒã€å¹Žäžã§ããå€èåã¯äºéã®æ¯èŠªã§ããäºéã¯ïŒïŒæ³ã§ãã
""")以äžã¯ãäžããããæç« ã衚ãå¯èœãªããŒã¿æ§é ã®äŸã§ãããã®åçã§äœ¿çšããèšèªã¯Pythonã§ãããä»ã®å€ãã®ããã°ã©ãã³ã°èšèªã«ãåæ§ã®æ¹æ³ãååšããŸãããŸããJSON圢åŒã®æåå衚çŸãçæãã颿°ãæäŸããŸãã
```python
import json
# å®çŸ©ãããŠãã人ç©
taro = {"name": "倪é", "age": None, "sibling": "äºé"}
jiro = {"name": "äºé", "age": 24, "siblings": ["倪é"]}
natsukozi = {"name": "å€èå", "relation_to": "äºé"}
# Taro is older than Jiro by 5 years
taro["age"] = jiro["age"] + 5
data = [taro, jiro, natsukozi]
def to_json(data):
return json.dumps(data, ensure_ascii=False)
print(to_json(data))
```
å®è¡çµæïŒ
```json
[{"name": "倪é", "age": 29, "sibling": "äºé"}, {"name": "äºé", "age": 24, "siblings": ["倪é"]}, {"name": "å€èå", "relation_to": "äºé"}]
```
泚æïŒãã®JSON圢åŒã§ã¯ãã倪éãã¯ãäºéãã®å
åŒã§ããããå€èåãã¯ãäºéãã®æ¯èŠªã§ããããšã瀺ããŠããŸããäžæ¹ã§ããäºéãã¯äœäººã®å
åŒå§ã§ãããäžæç¢ºã§ãããããé
åã«å€ãå«ãŸããŠããŸãããJSONãã©ãŒããããããå°ãæå®ããŠã¿ãŸãã
ask("""äžèšã®æç« ãJSON圢åŒã§ã¢ãŠããããããŠãã ãããå¿
ãäžèšã®ãã©ãŒãããã§ãå
šãŠã®ç»å Žäººç©ã«é¢ããŠåºåããŠãã ããã
## ãã©ãŒããã
{
"name": "<<åå>>",
"age": <<幎霢>>,
"family": ["<<å®¶æã®åå>>", ...]
}
## æç«
倪éãšäºéã¯å
効ã§ãã倪éã¯äºéããïŒã€å¹Žäžã§ããå€èåã¯äºéã®æ¯èŠªã§ããäºéã¯ïŒïŒæ³ã§ãã
""")以äžããäžããããæç« ããäœæããã JSON 圢åŒã§ãã
```json
[
{
"name": "倪é",
"age": 29,
"family": [
{"name": "äºé", "age": 24},
{"name": "å€èå", "age": null}
]
},
{
"name": "äºé",
"age": 24,
"family": [
{"name": "倪é", "age": 29},
{"name": "å€èå", "age": null}
]
},
{
"name": "å€èå",
"age": null,
"family": [
{"name": "倪é", "age": 29},
{"name": "äºé", "age": 24}
]
}
]
```æ¯èŒçæå³éãã«åºãŠããŸããã
ãããã«
以äžããèªã¿ããã ãããããšãããããŸããå°ãã§ãåèã«ãªãã°ãšæããŸãã
ãã䌌ããããªã³ã³ãã³ãã«èå³ãããã°ããã©ããŒããŠããã ãããšå¬ããã§ãïŒ
https://twitter.com/alexweberk
ä»å䜿ã£ã Colabã®ã³ãŒãã¯ãã¡ãã§ãã
åè
å ã®ã¢ãã«: https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat
AWQ ç: https://huggingface.co/TheBloke/deepseek-llm-67b-chat-AWQ
ã©ã€ã»ã³ã¹ã«ã€ããŠ: åçšå©çšå¯èœãªç¬èªã©ã€ã»ã³ã¹ https://github.com/deepseek-ai/deepseek-LLM/blob/main/LICENSE-MODEL