Skip to content

Add gpu-mode-tutorial from huggingface/gpu-mode-openenv (d3d8e7c)#426

Closed
kiankyars wants to merge 1 commit into
huggingface:mainfrom
kiankyars:add-gpu-mode-tutorial
Closed

Add gpu-mode-tutorial from huggingface/gpu-mode-openenv (d3d8e7c)#426
kiankyars wants to merge 1 commit into
huggingface:mainfrom
kiankyars:add-gpu-mode-tutorial

Conversation

@kiankyars

@kiankyars kiankyars commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

restores the gpu-mode-tutorial folder that was referenced in the readme (f5c5594) but never added. content copied from huggingface/gpu-mode-openenv at commit d3d8e7c - the same commit that was moved out of openenv per the hf repo history

sorry for the earlier pr spam

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Mar 7, 2026
@greptile-apps

greptile-apps Bot commented Mar 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR restores the gpu-mode-tutorial folder (originally from huggingface/gpu-mode-openenv at commit d3d8e7c) that was referenced in the README but never included in the repo. The content is tutorial material — four walkthrough guides, a Colab notebook, and example scripts — intended to help users go from environment setup through GRPO training on Wordle.

Tier 1 Issues (Fix Immediately):

  • repl_with_llm.py:43 — Commented-out debug import should be removed
  • repl_with_llm.py:60 — Typo in inline comment: "Inrecreased" should be "Increased"

Tier 2 Issues (Alignment Discussion Required):

  • wordle.py:357–376 — External reward computation (green/yellow/repetition scores) calculated client-side violates the "Rewards in environment" invariant. These auxiliary signals should be computed inside the environment boundary or pass through the server-side Transform pipeline, not in the training orchestration script. Requires @darktex review before merge.
  • 01-environments.md:239–275 — Architecture diagram and "Key Insight" callout teach the deprecated HTTP-only client-server interface pattern. Per INVARIANTS.md, WebSocket is the canonical protocol and HTTP is being deprecated (PR [PATCH] Deprecate HTTP in websockets #252). Tutorial content should prioritize WebSocket as primary. Requires @darktex review.

Confidence Score: 2/5

  • Not safe to merge as-is — contains one active invariant violation (external reward computation) and one architectural misalignment (deprecated HTTP diagram) that require human alignment review.
  • The PR is documentation/tutorial content with no changes to core library code, which limits blast radius. However, it contains two tier-2 alignment issues that violate or contradict INVARIANTS.md: (1) wordle.py computes auxiliary reward signals client-side rather than inside the environment boundary per §3, and (2) 01-environments.md teaches the deprecated HTTP-only communication pattern as primary rather than WebSocket per §4. Both require @darktex sign-off before merge. Additionally, two minor tier-1 mechanical fixes are needed (commented-out import and typo).
  • gpu-mode-tutorial/walkthrough/examples/wordle.py (external reward computation), gpu-mode-tutorial/walkthrough/01-environments.md (deprecated HTTP architecture diagram)

Sequence Diagram

sequenceDiagram
    participant T as GRPOTrainer
    participant R as rollout_func
    participant E as TextArenaEnv (Server)
    participant vLLM as vLLM

    T->>R: rollout_func(prompts)
    loop For each prompt
        R->>E: env.reset() [WebSocket /ws]
        E-->>R: StepResult(observation)
        loop Up to max_turns
            R->>vLLM: generate_rollout_completions(prompt_text)
            vLLM-->>R: prompt_ids, completion_ids, logprobs, text
            R->>E: env.step(TextArenaAction) [WebSocket /ws]
            E-->>R: StepResult(reward, observation, done)
            Note over R: ⚠️ green/yellow/repetition<br/>scores computed HERE<br/>(client-side — invariant violation)
        end
    end
    R-->>T: {prompt_ids, completion_ids, logprobs,<br/>correct_reward, green_reward, ...}
    T->>T: Optimize policy with reward_funcs
Loading

Last reviewed commit: 2018cfb


def create_qwen_llm():
"""Create an LLM function using the smallest Qwen instruct model."""
#from transformers import AutoModelForCausalLM, AutoTokenizer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Commented-out debug import should be removed.

Suggested change
#from transformers import AutoModelForCausalLM, AutoTokenizer
Prompt To Fix With AI
This is a comment left during a code review.
Path: gpu-mode-tutorial/walkthrough/examples/repl_with_llm.py
Line: 43

Comment:
Commented-out debug import should be removed.

```suggestion

```

How can I resolve this? If you propose a fix, please make it concise.

"""Generate response using Qwen model."""
response = client.chat.completions.create(
messages=messages,
max_tokens=2048, # Inrecreased for longer code responses

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo in inline comment: "Inrecreased" should be "Increased".

Prompt To Fix With AI
This is a comment left during a code review.
Path: gpu-mode-tutorial/walkthrough/examples/repl_with_llm.py
Line: 60

Comment:
Typo in inline comment: `"Inrecreased"` should be `"Increased"`.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +357 to +376
feedback = extract_wordle_feedback(observation)

# Update guess counts
previous_occurrences = guess_counts[guess]
repetition_score = scale_repetition_score(previous_occurrences, len(guess_counts))
guess_counts[guess] += 1

# calculate custom reward signals from the feedback
if not feedback:
green_score = 0.0
yellow_score = 0.0
else:
green_count, yellow_count = extract_feedback_counts(feedback)
green_score = green_count / 5.0
yellow_score = yellow_count / 5.0

repetition_scores.append(repetition_score)
green_scores.append(green_score)
yellow_scores.append(yellow_score)
correct_scores.append(correct_score)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ALIGNMENT FLAG: External reward computation violates "Rewards in environment" invariant.

  • Principle at stake: INVARIANTS.md §Architectural Invariants §3 ("Rewards in environment")
  • The concern: The rollout_once function computes auxiliary reward signals (green_score, yellow_score, repetition_score) entirely on the client side by parsing the raw observation text using helpers from the env package (lines 357–376). According to the architectural invariant, "Reward computation must stay inside environment boundary" and "External reward augmentation uses Transform pipeline" (server-side only). These auxiliary signals should not be calculated in the training orchestration script.
  • Suggested reviewer: @darktex
Prompt To Fix With AI
This is a comment left during a code review.
Path: gpu-mode-tutorial/walkthrough/examples/wordle.py
Line: 357-376

Comment:
**ALIGNMENT FLAG**: External reward computation violates "Rewards in environment" invariant.

- **Principle at stake**: INVARIANTS.md §Architectural Invariants §3 ("Rewards in environment")
- **The concern**: The `rollout_once` function computes auxiliary reward signals (`green_score`, `yellow_score`, `repetition_score`) entirely on the client side by parsing the raw observation text using helpers from the env package (lines 357–376). According to the architectural invariant, "Reward computation must stay inside environment boundary" and "External reward augmentation uses Transform pipeline" (server-side only). These auxiliary signals should not be calculated in the training orchestration script.
- **Suggested reviewer**: `@darktex`

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +239 to +275
┌────────────────────────────────────────────────────────────┐
│ YOUR TRAINING CODE │
│ │
│ env = OpenSpielEnv(...) ← Import the client │
│ result = env.reset() ← Type-safe! │
│ result = env.step(action) ← Type-safe! │
│ │
└─────────────────┬──────────────────────────────────────────┘
│ HTTP/JSON (Language-Agnostic)
│ POST /reset, POST /step, GET /state
┌─────────────────▼──────────────────────────────────────────┐
│ DOCKER CONTAINER │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ FastAPI Server │ │
│ │ └─ Environment (reset, step, state) │ │
│ │ └─ Your Game/Simulation Logic │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ Isolated • Reproducible • Secure │
└────────────────────────────────────────────────────────────┘
```

!!! info "Key Insight"
You never see HTTP details - just clean Python methods!

```python
env.reset() # Under the hood: HTTP POST to /reset
env.step(...) # Under the hood: HTTP POST to /step
env.state() # Under the hood: HTTP GET to /state
```

The magic? OpenEnv handles all the plumbing. You focus on RL! ✨

---

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ALIGNMENT FLAG: Architecture diagram depicts deprecated HTTP-only communication pattern.

  • Principle at stake: INVARIANTS.md §Architectural Invariants §4 ("Communication patterns")
  • The concern: The ASCII diagram (lines 239–262) and "Key Insight" callout (lines 264–271) present the client-server interface exclusively via HTTP POST /reset, HTTP POST /step, and HTTP GET /state. However, INVARIANTS.md explicitly states that WebSocket is the canonical protocol and HTTP is being deprecated in favor of WebSocket-only (PR [PATCH] Deprecate HTTP in websockets #252). While both protocols are currently available during the transition, tutorial content should teach the canonical WebSocket pattern as primary, with HTTP noted only as auxiliary or deprecated. This diagram may mislead newcomers about the current best practice.
  • Suggested reviewer: @darktex
Prompt To Fix With AI
This is a comment left during a code review.
Path: gpu-mode-tutorial/walkthrough/01-environments.md
Line: 239-275

Comment:
**ALIGNMENT FLAG**: Architecture diagram depicts deprecated HTTP-only communication pattern.

- **Principle at stake**: INVARIANTS.md §Architectural Invariants §4 ("Communication patterns")
- **The concern**: The ASCII diagram (lines 239–262) and "Key Insight" callout (lines 264–271) present the client-server interface exclusively via `HTTP POST /reset`, `HTTP POST /step`, and `HTTP GET /state`. However, INVARIANTS.md explicitly states that WebSocket is the canonical protocol and HTTP is being deprecated in favor of WebSocket-only (PR #252). While both protocols are currently available during the transition, tutorial content should teach the canonical WebSocket pattern as primary, with HTTP noted only as auxiliary or deprecated. This diagram may mislead newcomers about the current best practice.
- **Suggested reviewer**: `@darktex`

How can I resolve this? If you propose a fix, please make it concise.

@kiankyars kiankyars closed this Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant