Repository navigation
Studio: sort Translate languages and show style and tone on the page - #18220
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
#18237) ## Stop pinning the gc freeze count in test_external_freeze_is_left_alone `tests/test_gc_train_scope.py::test_external_freeze_is_left_alone` failed on a `Repo tests (CPU, rest)` run whose base already has every recent fix (#18220, a frontend-only PR): ``` E assert 1364742 == 1364744 E + where 1364742 = <built-in function get_freeze_count>() ``` ### Cause The test freezes the heap itself, runs `train()`, and asserts `gc.get_freeze_count()` is exactly what it was before. That count is not stable. An object in the permanent generation is still freed by refcounting, and CPython drops it from the count when it goes. So any frozen object released while `train()` runs lowers the count, and the assert fails with no change in behaviour. Here, two objects went. ```python gc.collect(); x = [[] for _ in range(5)]; gc.freeze(); b = gc.get_freeze_count(); del x # b = 12084, gc.get_freeze_count() = 12078 ``` The scope code in `unsloth/models/_gc_train_scope.py` is correct: it leaves a freeze it does not own alone. Only the test's way of checking that is wrong. ### Fix The test now checks the claim directly instead of comparing a counter that can move on its own: - It spies on `gc.collect`, `gc.freeze` and `gc.unfreeze` through the scope module, the same way `test_wrapper_captured_after_install_freezes_once` already does. - It asserts that `train()` called none of them. - It asserts that the heap is still frozen both inside `train()` and after it. A new test, `test_freeze_count_falls_when_a_frozen_object_is_freed`, pins the CPython behaviour above. It documents why the count is not compared. ### Verification - `tests/test_gc_train_scope.py`: 17 passed. - Sabotage checks: - Letting the scope freeze on top of an external freeze (dropping the `gc.get_freeze_count() > 0` early return) fails this test and `test_after_step_needs_an_owned_freeze`. - Making the scope always call `gc.unfreeze()` on exit fails this test. - `tests/python/test_accelerator_skip_guards.py` and `tests/studio/test_backend_ci_*.py` pass, and ruff is clean.
) ## Skip interpreter teardown in the DDP trainable-embeddings worker `tests/test_ddp_find_unused_default.py::test_trainable_embeddings_train_under_ddp_reentrant_checkpointing` has hung on `Repo tests (CPU, rest-2)` twice: on #12258, and on #18220, whose base is current `main`. ``` E Failed: ['.../tests/_ddp_trainable_embeddings_worker.py', '.../ddp'] hung past 150s: E [Gloo] Rank 0 is connected to 1 peer ranks. ... E RANK_OK find_unused=FalseRANK_OK find_unused=False ``` Both ranks had finished. They printed `RANK_OK` after writing their results, and then the processes never exited. Locally the whole test takes about 12 s. ### Cause After `RANK_OK`, `tests/_ddp_trainable_embeddings_worker.py` calls `dist.destroy_process_group()` and returns to normal interpreter teardown. The repo's other gloo workers do not do that. `tests/test_tp_native_gloo.py`, `test_tp_host_input_embedding_gloo.py`, `test_sharded_load_bnb4_gloo.py`, the `pp_*_gloo` workers and others all: - barrier before tearing the group down, because rank 0 hosts the TCPStore; - call `os._exit(0)` once results are saved, because interpreter teardown can wedge or abort on a gloo C++ thread after the work is done. This worker predates that pattern. That is the failure seen here: the run is finished, but the process never exits. I could not trigger the CI hang itself: 48 local torchrun launches, 8 in parallel, all exited 0. So the hang is shown with an injected teardown wedge (see Verification). ### Fix On the distributed path, after `RANK_OK`, the worker now does what the other gloo workers do: - `dist.barrier()`, then `dist.destroy_process_group()`; - flush stdout and stderr, then `os._exit(0)`. Nothing before `RANK_OK` changes. That includes the training steps, the result files and the single-process reference run. The test's assertions are unchanged, and a rank that fails before `RANK_OK` still exits non-zero. ### Verification - `tests/test_ddp_find_unused_default.py`: 63 passed. - Sabotage check: after `RANK_OK` on the distributed path, I injected a thread that never ends, standing in for a teardown thread that wedges. - `main`: `hung past 150s` with both `RANK_OK` lines printed, which is the CI signature. - This change: the test passes in 10.8 s. - ruff is clean.
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…18263) Addresses items 3 and 4 of #18198 (follow-up to #18220, which covered items 1, 2, 6 and the read aloud fallback). ## What changes - **Detected language on the source pill (item 4).** With "Detect language" selected, the pill now reads e.g. `Hindi (detected)` once the text is clear enough to tell, and goes back to `Detect language` when it is not. The pill stays in automatic mode; nothing is sent to the model differently. - **Swap with the detected language (item 3).** Swap was disabled in automatic mode. It now works like Google Translate and LibreTranslate: the detected language becomes the target, the old target becomes the source, and a finished translation moves into the text box (an edited draft is still never replaced). With nothing detected, or when the text is already in the target language, the button stays disabled with the same tooltip as before. ## How detection works `detect-language.ts`, no new dependency, runs on the first 2,000 characters on each edit (about 0.2 to 0.4 ms per call here): - Scripts only one Translate language uses decide alone: Korean, Thai, Khmer, Burmese, Tibetan, Hebrew, Bengali, Tamil, Telugu, Gujarati. Kana means Japanese. - Han text: Cantonese particles, else Traditional vs Simplified character forms (nothing when neither shows up, e.g. `你好`). - Arabic script: Uyghur and Urdu letters, else Persian vs Arabic letter forms. Cyrillic: Kazakh letters, Mongolian letters and words, else Ukrainian vs Russian letters and words. - Latin script and Devanagari: common function words plus letters only one language uses. It returns nothing unless one language clearly beats the runner-up, so a short or ambiguous text shows plain `Detect language` instead of a wrong guess. ## Accuracy Held-out FLORES-200 `devtest` (1,012 sentences per language, all 38 Translate languages; the word lists were tuned on `dev` only): | Input | Right | Wrong | Nothing shown | |---|---|---|---| | Full sentence | 92.1% | 2.7% | 5.2% | | First 5 words | 78.7% | 3.4% | 17.9% | | First 30 characters | 76.0% | 3.6% | 20.4% | Most of the "wrong" row is FLORES Cantonese, which is written as formal Chinese and comes back as Traditional Chinese (971 of 1,012). Without it, full sentences are wrong 0.2% of the time. Kazakh fragments that only show ө or ү plus і read as Kazakh, not Mongolian. Indonesian and Malay share most of their words, so those two usually show nothing rather than risk the other one. ## Tests - `tests/translate-detect-language.test.ts`: a sentence and a short phrase for every Translate language, the list kept in sync with `TRANSLATE_LANGUAGES`, and short / ambiguous inputs returning nothing. - `tests/translate-store.test.ts`: swap in automatic mode is a no-op without a detected language and swaps with one; it fails on main. - `npm run typecheck`, `npm run i18n:check:strict`, `vite build` and `npm run bundle:check` pass. The new `translate.detectedLanguage` key is in all 25 locales. ## Before / after (merge base ff6c71b vs head a1d9827, Chromium) Detect language selected, target English, a Hindi sentence typed. No model loaded, so only the pills and the Swap button are under test. **Source pill names the detected language; Swap is enabled** (before: `Detect language`, Swap disabled)  **After clicking Swap: source English, target Hindi** (before: nothing happens)  Fixes #18198
From #18198:
Language list sorted A to Z

Translate button stays visible on a small window (1280x650)

Style and Tone on the page, no longer inside Options

Before / after (merge base 6ec149e vs head 50b6bd0, Chromium)
Style and Tone on the page (Tone set to Formal after a click; aria-pressed follows it)

Options popover no longer holds Style and Tone

Translate to list sorted A to Z (38 languages, sorted false -> true)

1280x650 window: Translate button bottom 711 px (off screen) -> 596 px (on screen)
