Views
No views yet
150k steps) represents the "pre-decay" phase of training. It has been trained on short contexts with a high learning rate and is intended for architectural evaluation and research purposes.

trust_remote_code=True as this model utilizes custom modeling code (modeling_neuroblast.py).1import torch
2from transformers import AutoTokenizer, TextStreamer, AutoModelForCausalLM
3
4model_id = "mkurman/NeuroBLAST-V3-SYNTH-EC-150000"
5
6# Load the tokenizer
7tokenizer = AutoTokenizer.from_pretrained(model_id)
8
9# Load the model with custom code trust
10model = AutoModelForCausalLM.from_pretrained(
11 model_id,
12 torch_dtype=torch.bfloat16,
13 device_map='cuda',
14 trust_remote_code=True
15).eval()
16
17streamer = TextStreamer(
18 tokenizer, skip_prompt=False, decode_kwargs={"skip_special_tokens": False}
19)
20
21# Prepare input
22input_ids = tokenizer.apply_chat_template(
23 [{"role": "user", "content": "what is hypertension?"}],
24 tokenize=True,
25 return_tensors="pt",
26 add_generation_prompt=True
27)
28
29print(f"Input IDs: {input_ids}")
30
31# Generate
32with torch.no_grad():
33 outputs = model.generate(
34 input_ids=input_ids.to(model.device),
35 max_new_tokens=128,
36 streamer=streamer,
37 use_cache=True,
38 # Important: Keep repetition_penalty at 1.0 for this early checkpoint
39 repetition_penalty=1.0,
40 )
411
2import argparse
3import jax
4import jax.numpy as jnp
5from transformers import AutoTokenizer
6from neuroblast3_jax.modeling_neuroblast_jax import NeuroBLASTForCausalLM as NeuroBLASTForCausalLMJax
7
8def generate_text(model, tokenizer, text, max_new_tokens=50, temperature=0.7, top_k=50):
9 inputs = tokenizer(f"user\n{text}<|im_end|><|im_start|>assistant\n", return_tensors="np")
10 original_input_ids = inputs["input_ids"]
11 batch_size, prompt_len = original_input_ids.shape
12 total_len = prompt_len + max_new_tokens
13
14 # Pad input_ids to total_len
15 pad_id = tokenizer.pad_token_id if tokenizer.pad_token_id is not None else 0
16 input_ids = jnp.full((batch_size, total_len), pad_id, dtype=jnp.int32)
17 input_ids = input_ids.at[:, :prompt_len].set(original_input_ids)
18
19 attention_mask = jnp.ones((batch_size, total_len), dtype=jnp.int32)
20 params = model.params
21
22 @jax.jit
23 def model_step(params, input_ids, attention_mask, rng):
24 outputs = model(input_ids=input_ids, attention_mask=attention_mask, params=params, train=False)
25 return outputs.logits
26
27 rng = jax.random.PRNGKey(0)
28
29 print("Generating...")
30 current_len = prompt_len
31 printed_len = 0
32
33 for i in range(max_new_tokens):
34 rng, step_rng = jax.random.split(rng)
35
36 # Run model
37 logits = model_step(params, input_ids, attention_mask, step_rng)
38
39 # Get logits for the last valid token (current_len - 1)
40 next_token_logits = logits[:, current_len - 1, :]
41
42 # Sampling
43 scaled_logits = next_token_logits / temperature
44 next_token = jax.random.categorical(step_rng, scaled_logits, axis=-1)
45
46 # Update input_ids
47 # We need to update the next position
48 input_ids = input_ids.at[:, current_len].set(next_token)
49
50 current_len += 1
51
52 # Streaming output
53 valid_ids = input_ids[0, :current_len]
54 current_text = tokenizer.decode(valid_ids, skip_special_tokens=False)
55
56 if i == 0:
57 pass
58
59 new_text = current_text[printed_len:]
60 if new_text:
61 print(new_text, end="", flush=True)
62 printed_len += len(new_text)
63
64 # Check EOS
65 if next_token[0] == tokenizer.eos_token_id:
66 break
67
68 valid_ids = input_ids[0, :current_len]
69 return tokenizer.decode(valid_ids, skip_special_tokens=False)
70
71
72 checkpoint = "mkurman/NeuroBLAST-V3-SYNTH-EC-150000-JAX"
73
74 print(f"Loading model from {checkpoint}...")
75 tokenizer = AutoTokenizer.from_pretrained(
76 checkpoint,
77 use_fast=True,
78 trust_remote_code=True,
79 )
80
81 print(f"Available devices: {jax.devices()}")
82
83 model = NeuroBLASTForCausalLMJax.from_pretrained(
84 checkpoint,
85 dtype=jnp.bfloat16,
86 trust_remote_code=True,
87 is_decoder=True,
88 )
89
90 generated_text = generate_text(model, tokenizer, 'what is hypertension?', 128)
91
92 print("\nGenerated Text:")
93 print("-" * 20)
94 print(generated_text)
95 print("-" * 20)
96