-
Notifications
You must be signed in to change notification settings - Fork 70
[bugfix]dynemb export supports input_tile=3 #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eric-gecheng
wants to merge
1
commit into
alibaba:master
Choose a base branch
from
eric-gecheng:bugfix/dynemb_input_tile_3
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -445,6 +445,45 @@ def _a2a( | |
| m._buffers[name].copy_(new_meta) | ||
|
|
||
|
|
||
| # Module-name segments that get a `_user` twin when INPUT_TILE=3 export | ||
| # duplicates the embedding group into item/user halves. See | ||
| # tzrec/modules/embedding.py:EmbeddingGroupImpl / | ||
| # SequenceEmbeddingGroupImpl for the construction. | ||
| _INPUT_TILE_USER_SEGMENTS = frozenset({"ebc", "mc_ebc", "ec_dict", "mc_ec_dict"}) | ||
|
|
||
|
|
||
| def _link_dynamicemb_input_tile_user_paths(dynamicemb_path: str) -> None: | ||
| """Symlink user-side dynamicemb dirs added by INPUT_TILE=3 export. | ||
|
|
||
| Each entry under ``dynamicemb_path`` is a dotted module path. For | ||
| every entry containing a segment in ``_INPUT_TILE_USER_SEGMENTS``, | ||
| create a sibling symlink whose matching segment carries a ``_user`` | ||
| suffix so DynamicEmbLoad can resolve the twin path used by the | ||
| INPUT_TILE=3 model. | ||
| """ | ||
| for entry in os.listdir(dynamicemb_path): | ||
| full_path = os.path.join(dynamicemb_path, entry) | ||
| if os.path.islink(full_path) or not os.path.isdir(full_path): | ||
| continue | ||
| segs = entry.split(".") | ||
| for i, seg in enumerate(segs): | ||
| if seg not in _INPUT_TILE_USER_SEGMENTS: | ||
| continue | ||
| user_segs = list(segs) | ||
| user_segs[i] = f"{seg}_user" | ||
| user_entry = ".".join(user_segs) | ||
| user_path = os.path.join(dynamicemb_path, user_entry) | ||
| if os.path.lexists(user_path): | ||
| continue | ||
| try: | ||
| os.symlink(entry, user_path) | ||
| logger.info( | ||
| f"created INPUT_TILE=3 dynamicemb symlink {user_entry} -> {entry}" | ||
| ) | ||
| except OSError as e: | ||
| logger.warning(f"failed to create dynamicemb symlink {user_entry}: {e}") | ||
|
|
||
|
|
||
| def restore_model( | ||
| checkpoint_dir: str, | ||
| model: nn.Module, | ||
|
|
@@ -523,6 +562,19 @@ def restore_model( | |
|
|
||
| dynamicemb_path = os.path.join(checkpoint_dir, "dynamicemb") | ||
| if os.path.exists(dynamicemb_path): | ||
| # Training never sets INPUT_TILE, but exporting with | ||
| # INPUT_TILE=3 adds twin user-side modules (`ebc_user`, | ||
| # `mc_ebc_user`, `ec_dict_user`, `mc_ec_dict_user`) that | ||
| # share dynamic-embedding tables with their non-user | ||
| # counterparts. The checkpoint only has the non-user paths, | ||
| # so DynamicEmbLoad raises "can't find path to load" for | ||
| # the user-side ones. Symlink the missing twin paths. | ||
| input_tile = os.environ.get("INPUT_TILE", "") | ||
| if input_tile.startswith("3"): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider reusing |
||
| if int(os.environ.get("RANK", 0)) == 0: | ||
| _link_dynamicemb_input_tile_user_paths(dynamicemb_path) | ||
| if dist.is_initialized() and dist.get_world_size() > 1: | ||
| dist.barrier() | ||
| logger.info( | ||
| f"RANK[{os.environ.get('RANK', 0)}] restoring dynamic embedding..." | ||
| ) | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor defensive nit: if a single dotted entry ever contained more than one segment in
_INPUT_TILE_USER_SEGMENTS, this loop would create N separate symlinks (each renaming a different segment). In practice the construction inEmbeddingGroupImpl/SequenceEmbeddingGroupImplproduces only one such segment per path, so this is theoretical — but adding abreakafter a successful (or skipped-because-exists)os.symlinkwould make the intent explicit and match the construction-side rename.