Views
No views yet
| Hyperparameter | Value |
|---|---|
| Batch Size | 16 |
| Learning Rate | 1e-8 |
| Weight Decay | 0.1 |
| Number of Epochs | 6 |
| Gradient Accumulation Steps | 8 |
| Max Gradient Norm | 10.0 |
| Seed | 42 |
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4# Register the model architecture with AutoModel
5from mp_pretrain import ArgonneConfig, ArgonneModelParallel
6from transformers import AutoConfig, AutoModel, AutoModelForCausalLM
7
8# Create a wrapper class with _no_split_modules
9class ArgonneModelParallelWithDeviceMap(ArgonneModelParallel):
10 # Add modules that shouldn't be split across devices
11 _no_split_modules = ["attention", "mlp", "block", "layer"]
12
13# Register the model with Hugging Face's Auto classes
14AutoConfig.register("argonne", ArgonneConfig)
15AutoModel.register(ArgonneConfig, ArgonneModelParallel)
16AutoModelForCausalLM.register(ArgonneConfig, ArgonneModelParallelWithDeviceMap)
17
18def main():
19 # Load model and tokenizer using the Auto classes
20 model_dir = "PursuitOfDataScience/Argonne-1.0-Instruct"
21 tokenizer = AutoTokenizer.from_pretrained(model_dir)
22 model = AutoModelForCausalLM.from_pretrained(model_dir,
23 device_map="auto",
24 torch_dtype=torch.float16)
25
26 # Setup for inference
27 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
28 model = model.to(device)
29
30 # Add the 'devices' attribute that model.generate() expects
31 if not hasattr(model, 'devices'):
32 model.devices = [device]
33
34 # Set up pipeline stages to None if model was loaded without distribution
35 if not hasattr(model, 'pipeline_stages') or model.pipeline_stages is None:
36 model.pipeline_stages = None
37
38 # Generate text from a prompt
39 prompt = f"USER: Can you write a short introduction about economics?\n\nASSISTANT:"
40 # Extract just the input_ids from tokenizer output
41 input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device)
42
43 # Generate text
44 outputs = model.generate(
45 input_ids,
46 max_new_tokens=650,
47 temperature=0.7,
48 top_k=50
49 )
50
51 # Print the result
52 generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
53 print(f"Generated text:\n{generated_text}")
54
55if __name__ == "__main__":
56 main()USER: Can you write a short introduction about economics?
ASSISTANT: The concept of economic development has been going down in the West for far too long. The concept has been criticized, because it is not clear whether what was originally talked about can be justified.
CAN: Economic development had been going up in the West for far too long. Economics, the sciences, and mathematics were at the forefront of economic progress. And so economists and other scholars have been trying to understand and explain the process.
HORALD: We’re standing on the shoulders of giants. Economics, of course, is the study of the value of goods, value of money, value of goods, value of goods, and value of money.
ALWAY: If you were to study economics, it would be like studying a science. So economics is the study of value.
CONNECUS: So economics has been going down in the West for some very long time. The fact that economics is a science is an indication that it is a science. A science that studies value, it is a science that is a science.
OVER: So economics has been going up in the West for some very long time. Economics, for example, is a science. And economics has been going up in the West for some very long time.
CAN: One of the things that economists are trying to understand is that when something is said to be a good, that is, it is a good, it is a good. And economists are trying to understand that.
CAN: So economics is the study of value, it is the study of value. So economists are trying to understand price, how much a market will sell for a commodity or how much a market will sell for a commodity.
HORALD: So economists are trying to understand the value of money, value of goods, value of goods, value of goods, value of goods, value of goods.
ALWAY: Economists are trying to understand the value of money, value of goods.
CAN: So economists are trying to understand the value of money, value of goods, value of goods. And that is a good.
CAN: So economics is a science.
CAN: But economics is not the study of value, it is the study of value. I
It is a science.
ALWAY: Economists are trying to understand the value of money, value of goods and value of money.
CAN: But the value of money is not money. It is a value of goods, value of money.
CAN: But economists are trying to understand the value of money, value of goods, value of goods, value of goods and value of goods, value of goods and value of goods.
CAN: So economists are trying to understand the value of money.
CAN: But the value of money is not money. It is a value of goods.
CAN: But the value of goods is not money. It is a value of money.