-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[None][chore] optimize kv cache transfer for context TEP and gen DEP #7613
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
base: main
Are you sure you want to change the base?
Conversation
/bot run |
PR_Github #18035 [ run ] triggered by Bot |
📝 WalkthroughWalkthroughAdds DP-rank–aware gating for KV-cache send/recv in cache formatting paths, aligning senders and receivers by DupHeadFactor and DP ranks. Updates recipient selection logic, introduces early return when no send is needed, and extends/adjusts unit tests for MLA and non-MLA scenarios with DP enabled/disabled. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant CacheFormatter
participant Cluster as DP/TP/PP Config
participant Network
Caller->>CacheFormatter: format(request)
CacheFormatter->>Cluster: get self/dest ranks, DupHeadFactor
CacheFormatter->>CacheFormatter: needSendCache(self, dest, DupHeadFactor)
alt needSendCache == false
CacheFormatter-->>Caller: return (no allocation/send)
else needSendCache == true
CacheFormatter->>CacheFormatter: pickRecvConnections(selfDP, PeerDupHeadFactor)
CacheFormatter->>Network: send KV-cache to selected peers
Network-->>CacheFormatter: ack
CacheFormatter-->>Caller: return
end
note over CacheFormatter,Network: Gating uses (destDPRank % DupHeadFactor) == (selfTpRankInDpGroup % DupHeadFactor).<br/>Recipient selection uses (i % PeerDupHeadFactor) == (selfDPRank % PeerDupHeadFactor).
sequenceDiagram
autonumber
participant Caller
participant MLACacheFormatter as MLA CacheFormatter
participant Cluster as DP/TP/PP Config
participant Network
Caller->>MLACacheFormatter: format(request)
MLACacheFormatter->>Cluster: read self/dest TP/DP/PP, DupHeadFactor
MLACacheFormatter->>MLACacheFormatter: needSendCache(...) with DP-aware checks
alt no send
MLACacheFormatter-->>Caller: return
else send
MLACacheFormatter->>MLACacheFormatter: pickRecvConnections(dpRank-offset mapping)
MLACacheFormatter->>Network: send KV-cache to DP/PP-aligned targets
Network-->>MLACacheFormatter: ack
MLACacheFormatter-->>Caller: return
end
note over MLACacheFormatter: targetInfo mapping uses dpRank offset and mDomainTPSize for recipient indices.
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp (1)
173-206
: Layer-wise send to all connections may deadlock with DP-filtered recv.
unformat()
receives only frompickRecvConnections(...)
; here the layer-wise path always sends on every connection index, which can block when the peer won’trecv
some indices under DP gating.
- Restrict sends to a DP-aligned subset (mirror
pickRecvConnections
mapping for the destination).- Or introduce a
pickSendConnections(...)
helper and use it in both layer-wise and non-layer-wise paths.cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp (2)
163-179
: Send only to DP-aligned subset; current code risks over-sending and stalls.
pickRecvConnections(...)
narrows receivers toPP-domain
entries for the chosen TP slice, butformat()
sends on every connection index. Limit sends to the same subset derived fromdestDPRank
to prevent unmatched sends.@@ - auto targetInfo = executor::kv_cache::targetIRanks(destConfig, selfConfig, selfIdx); + auto targetInfo = executor::kv_cache::targetIRanks(destConfig, selfConfig, selfIdx); @@ - size_t const pPDomainSize = targetInfo.mDomainPPSize; + size_t const pPDomainSize = targetInfo.mDomainPPSize; TLLM_CHECK((cacheBlockSize * blockNum) % pPDomainSize == 0); auto const targetBufferSize = (cacheBlockSize * blockNum) / pPDomainSize; @@ auto* agentConnnecion = dynamic_cast<executor::kv_cache::AgentConnection const*>(connections[0]); @@ - // The size of outputSplitCaches should be equal to pPDomainSize + // The size of outputSplitCaches should be equal to pPDomainSize + // Compute sender indices aligned with the destination DP rank: [tpOffset .. tpOffset+ppSize) + std::vector<size_t> sendIndices; + { + int destDpRank = destConfig.getParallelConfig().mEnableAttentionDP ? destConfig.getParallelConfig().mDPrank : 0; + size_t const tpOffset = (destDpRank % targetInfo.mDomainTPSize) * targetInfo.mDomainPPSize; + sendIndices.resize(pPDomainSize); + std::iota(sendIndices.begin(), sendIndices.end(), tpOffset); + } @@ - if (connections.size() > 1) + if (sendIndices.size() > 1) { if (!common::getEnvEnableReceiveKVCacheParallel()) { TLLM_LOG_DEBUG("Disable parallel receiving of the KV cache."); - for (size_t i = 0; i < connections.size(); i++) + for (size_t i = 0; i < sendIndices.size(); i++) { - sendBufferFun(deviceId, i); + sendBufferFun(deviceId, sendIndices[i]); } } else { // concurrency num - auto concurrencyNum = std::min(std::max(static_cast<size_t>(1), bufferCoverTargetNum), pPDomainSize); + auto concurrencyNum = std::min(std::max(static_cast<size_t>(1), bufferCoverTargetNum), sendIndices.size()); - auto remainSendNum = connections.size(); + auto remainSendNum = sendIndices.size(); while (remainSendNum > 0) { auto sendConcurrencyNum = std::min(remainSendNum, concurrencyNum); std::vector<std::future<void>> futures; futures.reserve(sendConcurrencyNum); - for (size_t i = 0; i < sendConcurrencyNum; i++) + for (size_t i = 0; i < sendConcurrencyNum; i++) { - TLLM_CHECK((i + (connections.size() - remainSendNum)) < connections.size()); - futures.push_back(std::async( - std::launch::async, sendBufferFun, deviceId, i + (connections.size() - remainSendNum))); + size_t idx = i + (sendIndices.size() - remainSendNum); + TLLM_CHECK(idx < sendIndices.size()); + futures.push_back(std::async(std::launch::async, sendBufferFun, deviceId, sendIndices[idx])); } for (auto& future : futures) { future.get(); } remainSendNum -= sendConcurrencyNum; } } } else { - sendBufferFun(deviceId, 0); + TLLM_CHECK(!sendIndices.empty()); + sendBufferFun(deviceId, sendIndices[0]); }Also applies to: 250-289
563-568
: Bug: comparesselfConfig
twice; should comparedestConfig
for MLA head count.This always evaluates the same side and misses invalid dest configs.
- if ((selfConfig.getModelConfig().mNbKvHeadsPerLayer.at(0) != 1) - || (selfConfig.getModelConfig().mNbKvHeadsPerLayer.at(0) != 1)) + if ((selfConfig.getModelConfig().mNbKvHeadsPerLayer.at(0) != 1) + || (destConfig.getModelConfig().mNbKvHeadsPerLayer.at(0) != 1)) { TLLM_LOG_WARNING("MLACacheFormatter::inquireSupport: only support MLA"); return false; }
🧹 Nitpick comments (3)
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp (1)
131-137
: Receiver-subset sanity check.Nice DP-aware filter. Add an assertion to catch topology mismatches early.
@@ TLLM_CHECK(numConnections == targetInfo.mIRanks.size()); int selfDPRank = selfConfig.getParallelConfig().mEnableAttentionDP ? selfConfig.getParallelConfig().mDPrank : 0; std::vector<size_t> ret; for (int i = 0; i < targetInfo.mDomainTPSize; i++) { if ((i % targetInfo.mPeerDupHeadFactor) == (selfDPRank % targetInfo.mPeerDupHeadFactor)) { for (int j = 0; j < targetInfo.mDomainPPSize; j++) { ret.push_back((i * targetInfo.mDomainPPSize) + j); } } } + TLLM_CHECK(ret.size() * targetInfo.mPeerDupHeadFactor == numConnections); return ret;
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (1)
1-1
: Set required env for parallel send path in tests.PR requires
TRTLLM_PARALLEL_CACHE_SEND=1
. Consider setting it once in the test fixture setup to avoid accidental regressions on CI.Example (add to
AsymmetricalCacheTest::setUpCacheTransceiver()
before creating connection manager):@@ void setUpCacheTransceiver() { + setenv("TRTLLM_PARALLEL_CACHE_SEND", "1", 1); if (!(mIsContext || mIsGeneration)) { return; }
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp (1)
48-54
: Recv-indexing aligned to DP rank; add sanity checks.Add a bound/assert to ensure we get exactly PP-domain connections and avoid surprises if topology changes.
@@ - // targetInfo , mRanks [tpranks, ppranks] + // targetInfo.mIRanks is laid out as [tpRanks, ppRanks] int dpRank = selfConfig.getParallelConfig().mEnableAttentionDP ? selfConfig.getParallelConfig().mDPrank : 0; for (int i = 0; i < targetInfo.mDomainPPSize; i++) { ret.push_back(i + (dpRank % (targetInfo.mDomainTPSize)) * targetInfo.mDomainPPSize); } + TLLM_CHECK(ret.size() == static_cast<size_t>(targetInfo.mDomainPPSize)); return ret;
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
(2 hunks)cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
(3 hunks)cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh}
: Namespace closing braces must include a trailing comment with the namespace name (e.g., '} // namespace foo').
Prefer const or constexpr variables over #define for constants.
Declare variables that are not modified after initialization as const.
Avoid magic literals in code; except for 0, nullptr, true, false. Use named constants for comparisons and logic.
Use Allman brace style for formatting.
Place the semicolon of an empty for/while loop on a new line.
Bodies of switch/while/do-while/for must be compound statements (brace-delimited), and if/else must always be followed by brace-delimited statements.
Type names (e.g., classes) must be CamelCase starting with an uppercase letter (e.g., FooBar).
Local variables, methods, and namespaces use lowerCamelCase (e.g., localFooBar).
Non-magic-number global variables that are non-static and not in an anonymous namespace must be lowerCamelCase prefixed with 'g' (e.g., gDontUseGlobalFoos).
Non-magic-number globals that are static or in an anonymous namespace use lowerCamelCase prefixed with 's' (e.g., sMutableStaticGlobal).
Locally visible static variables use lowerCamelCase with 's' prefix (e.g., static std::once_flag sFlag).
Private/protected member variables use 'm' prefix with CamelCase (e.g., mNbFooValues). Public members may omit, but 'm' is encouraged for clarity.
Constants (enums, global constants, static constants, and function-scope magic/literal constants) use uppercase SNAKE_CASE with 'k' prefix (e.g., kDIGIT_NUM).
Function-scope constants that are not magic numbers or literals are named like non-constant variables (e.g., bool const pass = a && b).
If macros are necessary, name them in UPPER_SNAKE_CASE (e.g., FOO_VERSION) and prefer constants over #define.
Use LLVM clang-format; wrap lines at a maximum of 120 columns; use '// clang-format off/on' sparingly with justification.
Use smart pointers for heap allocations; prefer unique_ptr for sole ownership, shared_ptr for shared...
Files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
**/*.{cpp,cxx,cc,cu,h,hpp,hh,hxx,cuh}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
C++ filenames should be lowerCamelCase (first letter lowercase) and must be case-insensitive unique within a compilation target.
Files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
**/*.{h,hpp,hh,hxx,cpp,cxx,cc,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Use only spaces, no tabs; indent with 4 spaces.
Files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
**/*.{h,hpp,hh,hxx,cpp,cxx,cc}
: Prefer anonymous namespaces over 'static' for internal linkage of functions.
All templates (class/function/member/static) must be instantiated at least once; non-POD classes should have private data members.
Files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
**/*.{cpp,cxx,cc,h,hpp,hh,hxx,cu,cuh,py}
📄 CodeRabbit inference engine (CODING_GUIDELINES.md)
Prepend the NVIDIA Apache-2.0 copyright header with current year to the top of all source files (e.g., .cpp, .h, .cu, .py).
Files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp
🧠 Learnings (3)
📚 Learning: 2025-08-21T09:41:49.347Z
Learnt from: eopXD
PR: NVIDIA/TensorRT-LLM#6768
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:2010-2045
Timestamp: 2025-08-21T09:41:49.347Z
Learning: In cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, updateSequenceCacheBlockOffsets is specifically for updating bookkeeping when blocks are added during the context phase, not for refreshing offsets after detach operations. During detach operations, GenerationRequest::removeFrontBlock handles the necessary cache block bookkeeping internally.
Applied to files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
cpp/tensorrt_llm/batch_manager/cacheFormatter.cpp
📚 Learning: 2025-08-20T06:48:45.368Z
Learnt from: eopXD
PR: NVIDIA/TensorRT-LLM#6768
File: cpp/include/tensorrt_llm/batch_manager/kvCacheManager.h:0-0
Timestamp: 2025-08-20T06:48:45.368Z
Learning: In cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, updateSequenceCacheBlockOffsets is only called when adding a sequence, not during detach operations. During detach, the cache block bookkeeping is handled by GenerationRequest::removeFrontBlock.
Applied to files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
📚 Learning: 2025-08-14T21:04:50.248Z
Learnt from: thorjohnsen
PR: NVIDIA/TensorRT-LLM#6910
File: cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp:0-0
Timestamp: 2025-08-14T21:04:50.248Z
Learning: In KV cache onboarding logic during prefill in cpp/tensorrt_llm/batch_manager/kvCacheManager.cpp, when calculating which blocks fall within the attention window, use getTokensPerBlock() to advance token indices rather than block->getUniqueTokens().size(), because the calculation needs to consider the post-prefill state where blocks will be filled to capacity, not their current token count.
Applied to files:
cpp/tensorrt_llm/batch_manager/mlaCacheFormatter.cpp
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Pre-commit Check
🔇 Additional comments (3)
cpp/tests/unit_tests/multi_gpu/cacheTransceiverTest.cpp (3)
1389-1399
: New MLA+DP test matrix: good coverage.Instantiation looks fine and expands asymmetric cases.
1435-1439
: Additional NoMLA duplicate DP case: good.Complements the previous duplicate scenarios.
1809-1816
: Expectation flips match DP-rank–aligned gating.The true/false flips are consistent with
needSendCache
usingdestDPRank % dupHeadFactor == ...
.
PR_Github #18035 [ run ] completed with state |
64b71e2
to
ca88ef4
Compare
/bot run |
PR_Github #18136 [ run ] triggered by Bot |
PR_Github #18136 [ run ] completed with state |
6bed96d
to
ee6ea78
Compare
/bot run --add-multi-gpu-test |
PR_Github #18886 [ run ] triggered by Bot |
PR_Github #18886 [ run ] completed with state |
ee6ea78
to
3245895
Compare
/bot run |
PR_Github #18936 [ run ] triggered by Bot |
PR_Github #18936 [ run ] completed with state |
3245895
to
a61b7a2
Compare
/bot run |
cc07e2b
to
e196b53
Compare
/bot run --add-multi-gpu-test |
PR_Github #19306 [ run ] triggered by Bot |
PR_Github #19306 [ run ] completed with state |
e196b53
to
32e58a4
Compare
/bot run |
PR_Github #19465 [ run ] triggered by Bot |
PR_Github #19465 [ run ] completed with state |
32e58a4
to
18c701b
Compare
/bot run --add-multi-gpu-test |
PR_Github #19509 [ run ] triggered by Bot |
PR_Github #19509 [ run ] completed with state |
18c701b
to
a1e5749
Compare
/bot run --add-multi-gpu-test |
PR_Github #19625 [ run ] triggered by Bot |
PR_Github #19625 [ run ] completed with state |
a1e5749
to
1b1ffa6
Compare
/bot run --add-multi-gpu-test |
PR_Github #19643 [ run ] triggered by Bot |
PR_Github #19643 [ run ] completed with state |
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
Signed-off-by: Chuang Zhu <[email protected]>
1b1ffa6
to
834bdfc
Compare
/bot run --add-multi-gpu-test |
PR_Github #19673 [ run ] triggered by Bot |
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests
Description
When context TEP and gen DEP, each dp rank of gen will request kv cache from context tp rank0 before.
We changed it so that dp rank will request kv cache from context tp_rank = gen_dp_rank%tp_num.
need
TRTLLM_PARALLEL_CACHE_SEND=1
Test Coverage
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
/bot [-h] ['run', 'kill', 'skip', 'reuse-pipeline'] ...
Provide a user friendly way for developers to interact with a Jenkins server.
Run
/bot [-h|--help]
to print this help message.See details below for each supported subcommand.
run [--reuse-test (optional)pipeline-id --disable-fail-fast --skip-test --stage-list "A10-PyTorch-1, xxx" --gpu-type "A30, H100_PCIe" --test-backend "pytorch, cpp" --add-multi-gpu-test --only-multi-gpu-test --disable-multi-gpu-test --post-merge --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx" --detailed-log --debug(experimental)]
Launch build/test pipelines. All previously running jobs will be killed.
--reuse-test (optional)pipeline-id
(OPTIONAL) : Allow the new pipeline to reuse build artifacts and skip successful test stages from a specified pipeline or the last pipeline if no pipeline-id is indicated. If the Git commit ID has changed, this option will be always ignored. The DEFAULT behavior of the bot is to reuse build artifacts and successful test results from the last pipeline.--disable-reuse-test
(OPTIONAL) : Explicitly prevent the pipeline from reusing build artifacts and skipping successful test stages from a previous pipeline. Ensure that all builds and tests are run regardless of previous successes.--disable-fail-fast
(OPTIONAL) : Disable fail fast on build/tests/infra failures.--skip-test
(OPTIONAL) : Skip all test stages, but still run build stages, package stages and sanity check stages. Note: Does NOT update GitHub check status.--stage-list "A10-PyTorch-1, xxx"
(OPTIONAL) : Only run the specified test stages. Examples: "A10-PyTorch-1, xxx". Note: Does NOT update GitHub check status.--gpu-type "A30, H100_PCIe"
(OPTIONAL) : Only run the test stages on the specified GPU types. Examples: "A30, H100_PCIe". Note: Does NOT update GitHub check status.--test-backend "pytorch, cpp"
(OPTIONAL) : Skip test stages which don't match the specified backends. Only support [pytorch, cpp, tensorrt, triton]. Examples: "pytorch, cpp" (does not run test stages with tensorrt or triton backend). Note: Does NOT update GitHub pipeline status.--only-multi-gpu-test
(OPTIONAL) : Only run the multi-GPU tests. Note: Does NOT update GitHub check status.--disable-multi-gpu-test
(OPTIONAL) : Disable the multi-GPU tests. Note: Does NOT update GitHub check status.--add-multi-gpu-test
(OPTIONAL) : Force run the multi-GPU tests in addition to running L0 pre-merge pipeline.--post-merge
(OPTIONAL) : Run the L0 post-merge pipeline instead of the ordinary L0 pre-merge pipeline.--extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx"
(OPTIONAL) : Run the ordinary L0 pre-merge pipeline and specified test stages. Examples: --extra-stage "H100_PCIe-TensorRT-Post-Merge-1, xxx".--detailed-log
(OPTIONAL) : Enable flushing out all logs to the Jenkins console. This will significantly increase the log volume and may slow down the job.--debug
(OPTIONAL) : Experimental feature. Enable access to the CI container for debugging purpose. Note: Specify exactly one stage in thestage-list
parameter to access the appropriate container environment. Note: Does NOT update GitHub check status.For guidance on mapping tests to stage names, see
docs/source/reference/ci-overview.md
and the
scripts/test_to_stage_mapping.py
helper.kill
kill
Kill all running builds associated with pull request.
skip
skip --comment COMMENT
Skip testing for latest commit on pull request.
--comment "Reason for skipping build/test"
is required. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.reuse-pipeline
reuse-pipeline
Reuse a previous pipeline to validate current commit. This action will also kill all currently running builds associated with the pull request. IMPORTANT NOTE: This is dangerous since lack of user care and validation can cause top of tree to break.