Skip to content

feat: Adding fast token - #3181

Merged
terrykong merged 2 commits into
mainfrom
feat/fastokens-integration
Jul 23, 2026
Merged

terrykong merged 2 commits into
mainfrom
feat/fastokens-integration

Conversation

@arnavk-nvidia

@arnavk-nvidia arnavk-nvidia commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do ?

Integrate https://github.com/Atero-ai/fastokens

More references: https://www.crusoe.ai/resources/blog/reducing-ttft-by-cpumaxxing-tokenization

Issues

List issues that this PR closes (syntax):

Usage

  • You can potentially add a usage example below
# Add a code snippet demonstrating how to use this

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you run the unit tests and functional tests locally? Visit our Testing Guide for how to run tests
  • Did you add or update any necessary documentation? Visit our Document Development Guide for how to write, build and test the docs.

Additional Information

  • ...

@arnavk-nvidia
arnavk-nvidia requested review from a team as code owners July 13, 2026 16:17
@copy-pr-bot

copy-pr-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@arnavk-nvidia arnavk-nvidia added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Jul 13, 2026
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

/ok to test

@arnavk-nvidia, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @arnavk-nvidia . is there any perf data to understand the delta from this change?

should we add some unit test to sanity that this is interchangeable?

Comment thread nemo_rl/utils/fastokens.py Resolved
Comment thread pyproject.toml Resolved
Comment thread nemo_rl/environments/nemo_gym.py Resolved
@arnavk-nvidia
arnavk-nvidia requested a review from a team as a code owner July 14, 2026 17:45
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test d52cf71

Comment thread ray.sub Resolved
@arnavk-nvidia
arnavk-nvidia requested review from a team as code owners July 15, 2026 17:45
terrykong
terrykong previously approved these changes Jul 15, 2026
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test bd3a8e0

@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test fc12d76

@terrykong
terrykong enabled auto-merge (squash) July 16, 2026 21:33
@terrykong

Copy link
Copy Markdown
Collaborator

/ok to test 0442eee

@arnavk-nvidia
arnavk-nvidia force-pushed the feat/fastokens-integration branch 2 times, most recently from 960139d to 4ea8ee5 Compare July 17, 2026 22:09
@arnavk-nvidia
arnavk-nvidia requested a review from a team as a code owner July 17, 2026 22:09
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test d0a6d06

@terrykong

Copy link
Copy Markdown
Collaborator

looks like a test failure test_distillation_setup_nemo_gym_uses_deferred_vllm

          nemo_gym_actor = MagicMock()
          nemo_gym_actor._spinup.remote.return_value = "spinup-ref"
          nemo_gym_cls = MagicMock()
          nemo_gym_cls.options.return_value.remote.return_value = nemo_gym_actor
          runtime_env = {
              "py_executable": "/venv/bin/python",
              "env_vars": {
                  "VIRTUAL_ENV": "/venv",
                  "UV_PROJECT_ENVIRONMENT": "/venv",
              },
          }
      
          with (
              patch.object(distil_mod, "RayVirtualCluster", DummyCluster),
              patch.object(distil_mod, "Logger"),
              patch.object(distil_mod, "CheckpointManager") as mock_ckpt_mgr,
              patch.object(distil_mod, "StatefulDataLoader"),
              patch.object(distil_mod, "Policy", DummyPolicy),
              patch.object(distil_mod, "VllmGeneration", DummyVllmGeneration),
              patch.object(distil_mod, "NemoGym", nemo_gym_cls),
              patch.object(
                  distil_mod,
                  "make_actor_runtime_env",
                  return_value=runtime_env,
              ) as mock_runtime_env,
              patch.object(
                  distil_mod,
                  "get_nemo_gym_uv_cache_dir",
                  return_value="/opt/nemo-gym/.uv-cache",
              ),
              patch.object(
                  distil_mod,
                  "get_nemo_gym_venv_dir",
                  return_value="/opt/nemo-gym/venvs",
              ),
              patch.object(distil_mod, "ray") as mock_ray,
          ):
              mock_ckpt_mgr.return_value.get_latest_checkpoint_path.return_value = None
              mock_ckpt_mgr.return_value.get_resume_paths.return_value = (None, None)
              mock_ray.get_runtime_context.return_value.get_node_id.return_value = "a" * 56
              mock_ray.get.return_value = None
      
  >           result = distil_mod.setup(master_config, tokenizer, dataset, None)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  
  unit/algorithms/test_distillation.py:1170: 
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  ../nemo_rl/algorithms/distillation.py:549: in setup
      results = {k: f.result() for k, f in submitted.items()}
                    ^^^^^^^^^^
  /root/.local/share/uv/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py:456: in result
      return self.__get_result()
             ^^^^^^^^^^^^^^^^^^^
  /root/.local/share/uv/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py:401: in __get_result
      raise self._exception
  /root/.local/share/uv/python/cpython-3.13.13-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py:59: in run
      result = self.fn(*self.args, **self.kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  
      def init_nemo_gym():
          nemo_gym_dict = dict(env_configs["nemo_gym"])
          # These are NeMo-RL-side fields consumed by NemoGymConfig, not
          # NeMo-Gym global config entries.
          invalid_tool_call_patterns = nemo_gym_dict.pop(
              "invalid_tool_call_patterns", None
          )
          thinking_tags = nemo_gym_dict.pop("thinking_tags", None)
          # Pass prebuilt cache + venv dirs through the global config so the
          # gym reuses image-baked venvs instead of rebuilding them.
          uv_cache_dir = get_nemo_gym_uv_cache_dir()
          if uv_cache_dir is not None:
              nemo_gym_dict.setdefault("uv_cache_dir", uv_cache_dir)
          uv_venv_dir = get_nemo_gym_venv_dir()
          if uv_venv_dir is not None:
              nemo_gym_dict.setdefault("uv_venv_dir", uv_venv_dir)
          nemo_gym_cfg = NemoGymConfig(
              model_name=generation_config["model_name"],
              base_urls=deferred_vllm.dp_openai_server_base_urls,
              invalid_tool_call_patterns=invalid_tool_call_patterns,
              thinking_tags=thinking_tags,
  >           use_fastokens=bool(policy_config["tokenizer"].get("use_fastokens")),
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
              initial_global_config_dict=nemo_gym_dict,
          )
  E       KeyError: 'tokenizer'

https://github.com/NVIDIA-NeMo/RL/actions/runs/29619881113/job/88015414081?pr=3181

@arnavk-nvidia

@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 4db546e

terrykong
terrykong previously approved these changes Jul 18, 2026
@arnavk-nvidia
arnavk-nvidia requested a review from a team as a code owner July 20, 2026 19:06
@github-actions github-actions Bot added the Documentation Improvements or additions to documentation label Jul 20, 2026
@terrykong

Copy link
Copy Markdown
Collaborator

@arnavk-nvidia looks like maybe some issue with updating from latest main pulling in some changes? any chance you can rebase from main to make sure diff didn't pull in anything unexpected or a conflict was resolved in an unexpected way?

@arnavk-nvidia
arnavk-nvidia force-pushed the feat/fastokens-integration branch from 8e02b53 to 0e8d25b Compare July 20, 2026 20:21
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 0e8d25b

@arnavk-nvidia
arnavk-nvidia force-pushed the feat/fastokens-integration branch 2 times, most recently from fe0c3de to 29bff98 Compare July 22, 2026 21:12
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 29bff98

terrykong
terrykong previously approved these changes Jul 22, 2026
Add opt-in support for the fastokens Rust-backed BPE tokenizer (~10x faster

Signed-off-by: Arnav Kundu <[email protected]>
@arnavk-nvidia

Copy link
Copy Markdown
Contributor Author

/ok to test 7f3d85b

@arnavk-nvidia
arnavk-nvidia requested a review from terrykong July 23, 2026 21:08
@terrykong
terrykong merged commit a7cc1c4 into main Jul 23, 2026
82 checks passed
@terrykong
terrykong deleted the feat/fastokens-integration branch July 23, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) Documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants