|
165 | 165 | "metadata": {}, |
166 | 166 | "outputs": [], |
167 | 167 | "source": [ |
168 | | - "jax.distributed.initialize() # distributed.initialize should only be called once.\n", |
| 168 | + "jax.distributed.initialize() # distributed.initialize should only be called once.\n", |
169 | 169 | "jax.devices()" |
170 | 170 | ] |
171 | 171 | }, |
|
189 | 189 | "RUN_NAME = datetime.datetime.now().strftime(\"%Y-%m-%d-%H-%M-%S\")\n", |
190 | 190 | "MODEL_CHECKPOINT_PATH = f\"/tmp/checkpoints/{MODEL_NAME}/{RUN_NAME}/unscanned\"\n", |
191 | 191 | "\n", |
192 | | - "HF_TOKEN = userdata.get('HF_TOKEN')\n", |
| 192 | + "HF_TOKEN = userdata.get(\"HF_TOKEN\")\n", |
193 | 193 | "login(token=HF_TOKEN)\n", |
194 | 194 | "max_logging.log(\"Authenticated with Hugging Face successfully!\")" |
195 | 195 | ] |
|
211 | 211 | "source": [ |
212 | 212 | "%%capture\n", |
213 | 213 | "argv = [\n", |
214 | | - " \"\", # This is a placeholder, it's not actually used by the script's logic\n", |
| 214 | + " \"\", # This is a placeholder, it's not actually used by the script's logic\n", |
215 | 215 | " f\"{MAXTEXT_PKG_DIR}/configs/base.yml\",\n", |
216 | 216 | " f\"model_name={MODEL_NAME}\",\n", |
217 | 217 | " f\"base_output_directory={MODEL_CHECKPOINT_PATH}\",\n", |
218 | 218 | " f\"hf_access_token={HF_TOKEN}\",\n", |
219 | 219 | " \"use_multimodal=false\",\n", |
220 | | - " \"scan_layers=false\"\n", |
| 220 | + " \"scan_layers=false\",\n", |
221 | 221 | "]\n", |
222 | 222 | "\n", |
223 | 223 | "to_maxtext.main(argv)" |
|
250 | 250 | "source": [ |
251 | 251 | "%%capture\n", |
252 | 252 | "config = pyconfig.initialize(\n", |
253 | | - " [\"\", f\"{MAXTEXT_PKG_DIR}/configs/base.yml\"], \n", |
| 253 | + " [\"\", f\"{MAXTEXT_PKG_DIR}/configs/base.yml\"],\n", |
254 | 254 | " per_device_batch_size=1.0,\n", |
255 | 255 | " run_name=\"test\",\n", |
256 | 256 | " max_target_length=4,\n", |
|
339 | 339 | "\n", |
340 | 340 | "# Pad input_ids to max_target_length\n", |
341 | 341 | "padded_ids = np.zeros(config.max_target_length, dtype=np.int32)\n", |
342 | | - "padded_ids[:len(input_ids)] = input_ids\n", |
| 342 | + "padded_ids[: len(input_ids)] = input_ids\n", |
343 | 343 | "ids = np.asarray(padded_ids, dtype=np.int32)\n", |
344 | 344 | "\n", |
345 | 345 | "s = (config.global_batch_size_to_train_on, config.max_target_length)\n", |
|
349 | 349 | ")\n", |
350 | 350 | "\n", |
351 | 351 | "ids = np.stack([ids for _ in range(config.global_batch_size_to_train_on)])\n", |
352 | | - "max_logging.log(f\"input_ids={input_ids}, \\n\\nids={ids}, \\n\\ndecoder_segment_ids = {decoder_segment_ids}, \\n\\ndecoder_positions= {decoder_positions}\")" |
| 352 | + "max_logging.log(\n", |
| 353 | + " f\"input_ids={input_ids}, \\n\\nids={ids}, \\n\\ndecoder_segment_ids = {decoder_segment_ids}, \\n\\ndecoder_positions= {decoder_positions}\"\n", |
| 354 | + ")" |
353 | 355 | ] |
354 | 356 | }, |
355 | 357 | { |
|
370 | 372 | "outputs": [], |
371 | 373 | "source": [ |
372 | 374 | "full_train_logits = model.apply(\n", |
373 | | - " state.params,\n", |
374 | | - " ids,\n", |
375 | | - " decoder_positions,\n", |
376 | | - " decoder_segment_ids,\n", |
377 | | - " enable_dropout=False,\n", |
378 | | - " rngs={\"aqt\": init_rng},\n", |
| 375 | + " state.params,\n", |
| 376 | + " ids,\n", |
| 377 | + " decoder_positions,\n", |
| 378 | + " decoder_segment_ids,\n", |
| 379 | + " enable_dropout=False,\n", |
| 380 | + " rngs={\"aqt\": init_rng},\n", |
379 | 381 | ")\n", |
380 | 382 | "full_train_logits = jax.experimental.multihost_utils.process_allgather(full_train_logits)\n", |
381 | 383 | "max_logging.log(f\"{full_train_logits[0, 0, :]=}\")" |
|
397 | 399 | "outputs": [], |
398 | 400 | "source": [ |
399 | 401 | "selected_logits = jax.lax.dynamic_slice(\n", |
400 | | - " full_train_logits,\n", |
401 | | - " (0, 0, full_train_logits.shape[2]-2, 0),\n", |
402 | | - " (1, 1, 1, full_train_logits.shape[3])\n", |
| 402 | + " full_train_logits, (0, 0, full_train_logits.shape[2] - 2, 0), (1, 1, 1, full_train_logits.shape[3])\n", |
403 | 403 | ")\n", |
404 | 404 | "\n", |
405 | 405 | "# Consider the greedily sampled token\n", |
406 | 406 | "init_rng, new_rng = jax.random.split(init_rng)\n", |
407 | 407 | "first_generated_token = inference_utils.sampling(\n", |
408 | 408 | " selected_logits,\n", |
409 | 409 | " new_rng,\n", |
410 | | - " config.decode_sampling_strategy, #\"greedy\"\n", |
| 410 | + " config.decode_sampling_strategy, # \"greedy\"\n", |
411 | 411 | ")\n", |
412 | 412 | "output = tokenizer.decode([first_generated_token.item()])\n", |
413 | 413 | "max_logging.log(f\"Next predicted token is `{output}` for the input prompt: `{config.prompt}`.\")" |
|
0 commit comments