datedgptAgent commited on
Commit
a4a2484
·
verified ·
1 Parent(s): c5b56f3

Upload folder using huggingface_hub

Browse files
README.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - causal-lm
6
+ - llama
7
+ - instruction-tuned
8
+ - point-in-time
9
+ - dated
10
+ - lookahead-bias-free
11
+ pipeline_tag: text-generation
12
+ ---
13
+
14
+ # DatedGPT-2024-Instruct
15
+
16
+ **DatedGPT** is a family of point-in-time language models: each vintage is
17
+ trained only on data available up to its cutoff date, making it suitable for
18
+ lookahead-bias-free prediction and point-in-time analysis.
19
+
20
+ This is the **instruction-tuned chat model** with data up to **2024**.
21
+ For the base (pretrained) model, see
22
+ [datedgpt/datedgpt-2024-base](https://huggingface.co/datedgpt/datedgpt-2024-base).
23
+
24
+ | Property | Value |
25
+ |----------|-------|
26
+ | Architecture | LlamaForCausalLM |
27
+ | Parameters | ~1.3 B |
28
+ | Context length | 2048 |
29
+ | Vocab | 32,000 (SentencePiece) |
30
+ | Precision | bfloat16 |
31
+ | Data vintage | 2024 |
32
+
33
+ ## Chat template
34
+
35
+ The Llama-2-style chat template ships in `tokenizer_config.json` — apply it
36
+ with the tokenizer. The BOS token must come from the tokenizer, **not** as a
37
+ literal `"<s>"` string in your prompt text.
38
+
39
+ ```python
40
+ import torch
41
+ from transformers import AutoTokenizer, AutoModelForCausalLM
42
+
43
+ repo_id = "datedgpt/datedgpt-2024-instruct"
44
+ tokenizer = AutoTokenizer.from_pretrained(repo_id)
45
+ model = AutoModelForCausalLM.from_pretrained(repo_id, torch_dtype=torch.bfloat16, device_map="auto")
46
+
47
+ prompt = tokenizer.apply_chat_template(
48
+ [{"role": "user", "content": "What is the capital of France?"}],
49
+ tokenize=False,
50
+ )
51
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
52
+ output = model.generate(**inputs, max_new_tokens=128, do_sample=True,
53
+ temperature=0.7, top_p=0.95, use_cache=True,
54
+ eos_token_id=tokenizer.eos_token_id,
55
+ pad_token_id=tokenizer.eos_token_id)
56
+ print(tokenizer.decode(output[0, inputs["input_ids"].shape[-1]:], skip_special_tokens=True))
57
+ ```
58
+
59
+ ## Serving on HF Inference Endpoints
60
+
61
+ This repo ships a `handler.py` that applies the chat template server-side —
62
+ clients send plain text (or a messages list for multi-turn). Deploy with the
63
+ Default container on a bf16-capable GPU (A10G or better).
64
+
65
+ ## Limitations
66
+
67
+ - Knowledge limited to the 2024 data vintage.
68
+ - No RLHF or safety tuning; outputs can be confidently wrong.
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 1,
8
+ "eos_token_id": 2,
9
+ "head_dim": 128,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 2048,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 5504,
14
+ "max_position_embeddings": 2048,
15
+ "mlp_bias": false,
16
+ "model_type": "llama",
17
+ "num_attention_heads": 16,
18
+ "num_hidden_layers": 24,
19
+ "num_key_value_heads": 16,
20
+ "pretraining_tp": 1,
21
+ "rms_norm_eps": 1e-05,
22
+ "rope_scaling": null,
23
+ "rope_theta": 10000.0,
24
+ "tie_word_embeddings": false,
25
+ "torch_dtype": "bfloat16",
26
+ "transformers_version": "4.51.0",
27
+ "use_cache": false,
28
+ "vocab_size": 32000
29
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 1,
4
+ "eos_token_id": 2,
5
+ "transformers_version": "4.51.0"
6
+ }
handler.py ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+
6
+ class EndpointHandler:
7
+ """
8
+ Hugging Face Inference Endpoints custom handler.
9
+
10
+ Expects input like:
11
+ - {"inputs": "hello"} -> single-turn, auto-wrapped with chat template
12
+ - {"inputs": [{"role":"user","content":"hello"}, ...]} -> multi-turn chat (messages list)
13
+ - {"inputs": "hello", "parameters": {"raw": true}} -> sent as-is (no template)
14
+
15
+ Optional:
16
+ - {"parameters": {"max_new_tokens": 512, "temperature": 0.7, ...}}
17
+ """
18
+
19
+ def __init__(self, path: str = ""):
20
+ model_dir = path or os.getenv("HF_MODEL_DIR", ".")
21
+ self.device = "cuda" if torch.cuda.is_available() else "cpu"
22
+
23
+ self.tokenizer = AutoTokenizer.from_pretrained(model_dir, trust_remote_code=True)
24
+
25
+ # Ensure pad token exists (common for causal LMs)
26
+ if self.tokenizer.pad_token is None:
27
+ self.tokenizer.pad_token = self.tokenizer.eos_token
28
+ self.tokenizer.pad_token_id = self.tokenizer.eos_token_id
29
+
30
+
31
+ self.model = AutoModelForCausalLM.from_pretrained(
32
+ model_dir,
33
+ torch_dtype="auto",
34
+ device_map="auto" if torch.cuda.is_available() else None,
35
+ trust_remote_code=True,
36
+ )
37
+ self.model.eval()
38
+
39
+ def __call__(self, data: dict) -> dict:
40
+ inputs = data.get("inputs", data)
41
+ params = data.get("parameters", {}) or {}
42
+
43
+ raw = bool(params.pop("raw", False))
44
+
45
+ if raw:
46
+ if not isinstance(inputs, str):
47
+ raise ValueError("raw mode requires inputs to be a string.")
48
+ prompt = inputs
49
+ elif isinstance(inputs, list):
50
+ # Multi-turn: inputs is a list of {"role": ..., "content": ...}
51
+ prompt = self.tokenizer.apply_chat_template(
52
+ inputs, tokenize=False,
53
+ )
54
+ elif isinstance(inputs, str):
55
+ # Single-turn: wrap in a one-message list
56
+ prompt = self.tokenizer.apply_chat_template(
57
+ [{"role": "user", "content": inputs}],
58
+ tokenize=False,
59
+ )
60
+ else:
61
+ raise ValueError("inputs must be a string or a list of messages.")
62
+
63
+ enc = self.tokenizer(
64
+ prompt,
65
+ return_tensors="pt",
66
+ padding=False,
67
+ truncation=True,
68
+ )
69
+ input_ids = enc["input_ids"].to(self.model.device)
70
+ attention_mask = enc.get("attention_mask", torch.ones_like(input_ids)).to(self.model.device)
71
+
72
+ gen_kwargs = {
73
+ "max_new_tokens": int(params.pop("max_new_tokens", 2048)),
74
+ "do_sample": bool(params.pop("do_sample", True)),
75
+ "temperature": float(params.pop("temperature", 0.7)),
76
+ "top_p": float(params.pop("top_p", 0.95)),
77
+ "repetition_penalty": float(params.pop("repetition_penalty", 1.2)),
78
+ "eos_token_id": self.tokenizer.eos_token_id,
79
+ "pad_token_id": self.tokenizer.pad_token_id,
80
+ }
81
+ gen_kwargs.update(params)
82
+
83
+ with torch.no_grad():
84
+ out = self.model.generate(
85
+ input_ids=input_ids,
86
+ attention_mask=attention_mask,
87
+ **gen_kwargs,
88
+ )
89
+
90
+ # Return only newly generated tokens (your current behavior)
91
+ new_tokens = out[0, input_ids.shape[-1]:]
92
+ text = self.tokenizer.decode(new_tokens, skip_special_tokens=True)
93
+
94
+ return {"generated_text": text}
95
+
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b34b177b28b9325e7294c7b25d998c8ae3053b165fc2b5136a42e63592ef5d3a
3
+ size 2690871976
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ accelerate
2
+ safetensors
special_tokens_map.json ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<s>",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "</s>",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": {
17
+ "content": "</s>",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "unk_token": {
24
+ "content": "<unk>",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ }
30
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": null,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ }
30
+ },
31
+ "bos_token": "<s>",
32
+ "chat_template": "{% if messages[0]['role'] == 'system' %}{% set loop_messages = messages[1:] %}{% set system_message = messages[0]['content'] %}{% else %}{% set loop_messages = messages %}{% endif %}{% for message in loop_messages %}{% if loop.index0 == 0 and system_message is defined %}{% set content = '<<SYS>>\n' + system_message + '\n<</SYS>>\n\n' + message['content'] %}{% else %}{% set content = message['content'] %}{% endif %}{% if message['role'] == 'user' %}{{ '<s>' + '[INST] ' + content + ' [/INST]' }}{% elif message['role'] == 'assistant' %}{{ content + '</s>' }}{% endif %}{% endfor %}",
33
+ "clean_up_tokenization_spaces": false,
34
+ "eos_token": "</s>",
35
+ "extra_special_tokens": {},
36
+ "legacy": false,
37
+ "model_max_length": 2048,
38
+ "pad_token": "</s>",
39
+ "padding_side": "right",
40
+ "sp_model_kwargs": {},
41
+ "split_special_tokens": false,
42
+ "tokenizer_class": "LlamaTokenizer",
43
+ "unk_token": "<unk>",
44
+ "use_default_system_prompt": false
45
+ }