# Enhancing Large Language Model Performance To Answer Questions and Extract
Information More Accurately

Liang Zhang, Katherine Jijo, Spurthi Setty, Eden Chung,
Fatima Javid, Natan Vidra, Tommy Clifford

###### Abstract

Large Language Models (LLMs) generate responses to questions; however, their
effectiveness is often hindered by sub-optimal quality of answers and
occasional failures to provide accurate responses to questions. To address
these challenges, a fine-tuning process is employed, involving feedback and
examples to refine models. The objective is to enhance AI models through
continuous feedback loops, utilizing metrics such as cosine similarity, LLM
evaluation and Rouge-L scores to evaluate the models. Leveraging LLMs like
GPT-3.5, GPT4ALL, and LLaMA2, and Claude, this approach is benchmarked on
financial datasets, including the FinanceBench and RAG Instruct Benchmark
Tester Dataset, illustrating the necessity of fine-tuning. The results
showcase the capability of fine-tuned models to surpass the accuracy of zero-
shot LLMs, providing superior question and answering capabilities. Notably,
the combination of fine-tuning the LLM with a process known as Retrieval
Augmented Generation (RAG) proves to generate responses with improved
accuracy.

##  1 Introduction

In the world of language models like ChatGPT, a significant challenge is
figuring out if these models’ responses are correct or if the models are
hallucinating—providing random or incorrect answers. Large Language Models
(LLMs) represent a significant leap in deep learning, characterized by their
expansive size and pre-training on diverse datasets. Built on the transformer
architecture, LLMs such as GPT-3 and ChatGPT, possess encoder and decoder
components with self-attention capabilities, enabling them to extract meanings
and comprehend relationships within text sequences. The unsupervised training
of transformer LLMs facilitates self-learning, encompassing basic grammar,
languages, and knowledge. The scalability of the transformer architecture
accommodates very large models, often containing billions of parameters,
capable of ingesting extensive datasets from diverse sources. The versatility
of LLMs is showcased in their ability to perform tasks ranging from question
answering to code generation. Once LLMs complete their initial training, they
possess the remarkable capability of adapting to various tasks through a
process known as fine-tuning. Fine-tuning involves adjusting the model’s
parameters using additional, more specific data, allowing it to specialize in
a particular application. For example, with a singular LLM such as GPT-3, it
can be fine-tuned for various use cases, such as answering questions in
different industries such as finance or healthcare, or answering questions in
simple terms for elementary school-level students. There are three common
learning models that showcase the versatility of LLMs: zero-shot learning,
where the base models can respond broadly to various requests without specific
training; few-shot learning, where providing a small set of relevant examples
significantly improves performance in a specific area; and fine-tuning, which
extends few-shot learning by allowing data scientists to train the base model
with additional data tailored to the specific application, refining its
parameters for optimal performance in diverse tasks. This adaptability makes
LLMs powerful tools that can be fine-tuned to excel in specific domains and
meet varied requirements effectively.

The current concern with the employment of LLMs is the notion of
hallucinations and their implications. LLMs tend to distort information or
offer inaccurate answers. In real-world applications, the discrepancies in the
information that a model provides due to hallucinations will have significant
consequences. Consider a situation where a financial analyst consults a large
language model regarding a company’s fiscal data, particularly inquiring about
the reported revenue. The correct answer is ”2.37M,” reflecting 2.37 million
dollars. However, due to hallucination, the model might answer with an altered
value, such as ”23.7M.” A subtle shift in a decimal point, due to
hallucination, drastically distorts the representation of the reported
revenue, presenting an exaggerated and false figure.

In the realm of financial decision-making, where numerical accuracy is
paramount - relying on inaccurate data to drive decisions will result in
misguided investment choices, financial planning errors, or misjudgments of a
company’s performance. It is imperative to resolve hallucination through the
application of methods like fine-tuning to allow language models to provide
reliable information in domains where the stakes are high and accuracy is
crucial.

##  2 Background

To understand different techniques to enhance large language model performance
to extract information and answer questions more accurately, we looked into
information about RAG, Fine Tuning, PEFT, LORA, QLORA and other methods.

###  2.1 Retrieval Augmented Generation

Retrieval Augmented generation (RAG) emerges as a crucial process in
optimizing the output of large language models. LLMs, with their vast training
data and billions of parameters, excel at tasks like question answering,
language translation, and sentence completion. However, inherent challenges
include the generation of inaccurate or outdated responses, presenting false
information, and a lack of adaptability to current events. RAG addresses these
issues by extending the capabilities of LLMs to reference authoritative
knowledge bases outside their training data, enhancing relevance, accuracy,
and usefulness in various contexts. RAG takes an input, retrieves a set of
relevant/supporting documents from a source like for example your textbook
pdf, and combines them with the original input prompt. This concatenated
context is then fed to the text generator, producing the final output. This
adaptability of RAG becomes valuable in situations where facts may change over
time, a feature particularly useful as the parametric knowledge of LLMs
remains static. RAG eliminates the need for retraining, allowing language
models to access the latest information for generating reliable outputs
through retrieval-based generation. introduced in “Retrieval-Augmented
Generation for Knowledge-Intensive NLP Tasks ” 111Patrick Lewis, Ethan Perez,
Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich
Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, Douwe
Kiela. Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks, 2020.

The RAG model faces many limitations that impact its effectiveness in
knowledge-intensive natural language processing tasks. Semantic search, a core
component of RAG, exhibits challenges such as retrieving irrelevant or
opposing information, indicating the model’s sensitivity to language nuances
and the potential for unexpected results. The ambiguity in understanding how
the embedding model extracts and organizes information in vectors adds
complexity to optimizing similarity functions. Additionally, the process of
chunking, crucial in RAG, can result in information loss if not carefully
designed. 222Disadvantages of RAG.
<EMAIL_ADDRESS>Accessed
on 2024-01-24.

Figure 1: Retrieval-Augmented Generation444Retrieval Augmented Generation
(RAG). https://docs.aws.amazon.com/sagemaker/latest/dg/jumpstart-foundation-
models-customize-rag.html

###  2.2 Fine Tuning

While Retrieval Augmented Generation provides a method of injecting new
knowledge sources into the LLM, the model itself remains unchanged which is
why RAG alone has subpar results on very domain specific data. LLMs like GPT
or LLaMA are not trained with a specific purpose in mind, yet many users would
like to use LLMs for a specific purpose; in our case, we wanted to achieve
domain-specific question answering from documents. Fine-tuning enables us to
customize the output of the model based on specific use cases without having
to go through the entire training process again. Actual fine-tuning alters the
weights of the model based on the additional fine-tuning data, while RAG edits
the query without making any changes to the model. So, a combination of these
two methods could optimize the model for a specific use-case. There are
various methods for fine-tuning large language models, such as Supervised
Fine-tuning (SFT) via Parameter Efficient Fine Tuning (PEFT)

Supervised Fine-tuning is when the training data consists of paired input and
outputs of various examples that demonstrate how you want the model to respond
to certain queries. By fine-tuning the model, we aim to get the model to mimic
the style of the training data when asked questions similar to those in the
data. Since our goal for the fine-tuned model was to be good at answering
questions on financial documents, our training data consisted of a set of
questions and answers curated by human financial experts. The datasets we
employed were meant for supervised fine-tuning as they consisted of a
question, context, and answer column.

Parameter Efficient Fine Tuning is a method that significantly reduces the
amount of compute and memory required for Fine Tuning LLMs. Instead of
retraining and adjusting all the weights, PEFT freezes all the weights of the
pre-trained model and then augments it with additional parameters during the
fine tuning process. This differs from full fine tuning which retrains all the
parameter weights, and transfer learning which only retrains the head of the
model. PEFT can result in comparable performance to fully fine tuned models
while having significantly less trainable parameters. It also reduces the risk
of a model forgetting a lot of core material and enables the same base model
to be fine tuned for various different use cases since the all the base pre-
trained weights remain fixed. 555 Sourab Mangrulkar and Sayak Paul,
“Parameter-Efficient Fine-Tuning Using PEFT,” Parameter-Efficient Fine-Tuning
using PEFT, February 10, 2023, https://huggingface.co/blog/peft.

Low Rank Adaptation (LoRA) is a method within PEFT that further reduces the
number of trainable parameters through the use of low-rank matrices. Instead
of representing the weights in a d x d matrix for example, LoRA represents it
as the product of (d x r)(r x d), where r is a rank significantly lower than
d. Compared to full fine tuning, LoRA uses 10000 times less trainable
parameters and three times less memory. 666Edward Hu, Yelong Shen, Phillip
Wallis, Zeyuan Allen-Zhu, Yuanzhi Li Shean Wang Lu Wang Weizhu Chen, LORA:
LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS, 2021 PEFT with LoRA is
significantly less computationally expensive that full fine tuning and has
been proven to result in comparable performance, as seen in Figure 2.
Therefore, such techniques have been widely adapted and the ability to fine
tune LLMs for specific use cases has been dramatically democratized.

QLoRA, or Quantized Low-Rank Adaptation is a method that further increases the
efficiency of fine tuning by significantly reducing the memory required while
preserving performance through the use of quantization. Tensors in these
models are usually in 16-bit precision and a quantized model then reduces the
precision and memory of these models, usually to 4-bit precision. QLoRA
quantizes each input tensor of the neural network and backpropagates gradients
through a this quantized model into Low Rank Adapters. 777Tim Dettmers,
Artidoro Pagnoni,Ari Holtzman Luke Zettlemoyer, QLORA: Efficient Finetuning of
Quantized LLMs, 2023

Figure 2: Fine Tuning Methods and LoRA performance 99footnotemark: 9 Figure 3:
Parameter Efficient Fine Tuning 1111footnotemark: 11

##  3 Process and Work

To enhance the accuracy of question and answer (Q&A) tasks, our approach
included supervised fine-tuning on the zero-shot model for GPT-3.5 Turbo. This
is needed because zero shot Retrieval-Augmented Generation (RAG) oftentimes
retrieves irrelevant information or irrelevant embeddings. Subsequently, we
utilized reprompting on GPT4All and Llama2 for further refinement. This
process included feeding in example prompts with given questions, evidence
text, and answers to guide the model in learning specific response patterns.
Additionally, we benchmarked the fine-tuning process by incorporating the
Retrieval-Augmented Generation (RAG) technique for Q&A tasks, thereby
enhancing the evaluation and overall performance of the models.

There is an absence in standardized methodologies for evaluating model
performance. We assessed the zero-shot model (LLM without fine-tuning) and
subsequently evaluated the model with fine-tuning and reprompting. The
approach involved iterative accuracy evaluation, incorporating fine-tuning or
reprompting into models such as GPT-3.5 Turbo, GPT4All, Llama2, and Claude.
The evaluation metrics used were cosine similarity and Rouge-L, measuring
accuracy in each iteration

###  3.1 Datasets

For fine-tuning and testing, we utilized two question-answering datasets.
FinanceBench is a novel benchmark developed by Patronus AI for evaluating the
performance of LLMs on open-book financial question answering. The dataset is
comprised of 10,231 questions about publicly traded companies. Each question
is accompanied by corresponding answers and evidence strings. It covers 40
companies in the USA, spanning 361 public filings, including 10Ks, 10Qs, 8Ks,
and Earnings Reports, released between 2015 and 2023. A typical entry contains
the question (e.g., “What Was AMCOR’s Adjusted Non-GAAP EBITDA for FY 2023”),
the answer (e.g., “AMCOR’s Adj. EBITDA was 2,018 million USD in FY 2023”), an
evidence string (containing information needed to verify the answer), and a
page number from the relevant document. The second dataset is RAG Instruct
Benchmark tester, designed by LLMWARE to measure the different capabilities of
retrieval augmented generation in financial and legal enterprise use cases.
The dataset includes 200 questions with context passages pulled from common
’retrieval scenarios’, e.g., financial news, earnings releases, contracts,
invoices, technical articles, general news and short texts. The questions,
spanning Core Q&A Evaluation, Not Found Classification, Boolean - Yes/No,
Math, Complex Q&A and Summary categories, are strategically segmented to
assess the capabilities of LLMs.

Figure 4: Sample of FinanceBench Dataset 131313Finance Bench Dataset.
https://huggingface.co/datasets/PatronusAI/financebench, Accessed on
2023-01-24 Figure 5: Sample of RAG Instruct Benchmark Tester Dataset
151515rag_instruct_benchmark_tester Dataset.
https://huggingface.co/datasets/llmware/rag_instruct_benchmark_tester,
Accessed on 2023-01-24

###  3.2 Data Preprocessing

The data had to be formatted in a very specific way for fine-tuning each large
language model. Both open-source LLMs like LLaMA-2 and closed LLMs like
GPT-3.5 have a certain format that the prompt and data must be presented based
on the way the model was developed. This process involved concatenating the
different columns from the data sets in a specific way as well as
incorporating any sort of prompt engineering.

For example, the LLaMA-2 model requires data in the following format:

⬇

<s>[INST] <<SYS>>\n{system_prompt}\n<</SYS>>\n\n{user_prompt} {input_section}
[/INST] {model_answer} </s>

The meta tags specify user vs. system. Instructions give the model a lot more
direction and yield much better results than just arbitrarily concatenating
the different columns. Within the system text, we can utilize prompt
engineering techniques to assign the LLM a specific role that will make it
behave in a certain way. For example, when fine-tuning LLaMA-2 on the
FinanceBench Dataset, the following prompt was used:

”You are a financial chatbot trained to answer questions based on the
information provided in 10-K documents. Your responses should be directly
sourced from the content of these documents. When asked a question, ensure
that your answer is explicitly supported by the text in the 10-K filing, and
do not include any external information, interpretations, or assumptions not
clearly stated in the document. If a question pertains to financial data or
analysis that is not explicitly covered in the 10-K filing provided, respond
by stating that the information is not available in the document. Your primary
focus should be on accuracy, specificity, and adherence to the information in
10-K documents, particularly regarding financial statements, company
performance, and market positions”

This is an example of how prompt engineering can help reduce hallucination as
it is very clearly specified that the model should not make up information if
the answer is not found in the provided context. For this use case, we
prioritize accuracy over creativity based on the context of how a model like
this will be used. Experimenting with prompt engineering within the fine-
tuning data provides another method to optimize these models for specific use
cases.

The user prompt is what is said to the model by the user and consists of both
the question itself and the provided context. All of that is surrounded by
instruction brackets to indicate to the model that it was all input, and based
on said instructions, it should provide an output. In the training data, the
answer is concatenated after the instruction tag is closed. For model
inference, all the input text is fed into the model the same way as it was
formatted in the training data, where the model is given everything within the
[INST] brackets, and infers the response.

##  4 Approach

In order to enhance the existing LLMs, we must improve both the models’
abilities to answer questions from a given context and their abilities to
retrieve the most relevant context. The specific use case we have in mind is
the ability to answer questions on financial documents, so the model must know
how to answer finance-related questions and where in the documents to find the
correct answers. We will go over our approach to improve both of these aspects
through human feedback and other techniques

###  4.1 Enhancing Question-Answering

The datasets we worked with had various questions, answers, and contexts
curated by human experts. Each row with all this information can be thought of
as a label, and we wanted to see how well the model improves after
incrementally increasing the number of labels it is given. For the
FinanceBench Dataset, we utilized this method for 4 LLMs: Claude, GPT 3.5
Turbo, GPT4ALL, and LLaMA-2. For Claude and GPT4ALL, the model weights were
not available to be fine-tuned, so we included the labels via few-shot
prompting. This means that all the human-labeled examples from the dataset
were included in the query itself, but none of the model weights were actually
modified. GPT 3.5 Turbo was fine-tuned via the OpenAI API on training data of
varying lengths in the proper jsonl format required by the docs. Finally,
LLaMA-2 is an open-source model available on the HuggingFace Hub (after
authorization), and was fine-tuned using the HuggingFace Transformer’s Trainer
class. We incremented the number of training labels, with each increment by
10m to a total of 50 labels and conducted model inference on all fixed test
rows of the FinanceBench Dataset.

Essentially, for each LLM we developed 5 different versions with 10, 20, 30,
40 and 50 labels included as training data respectively. The training process
for each version was the same, the only difference being the number of human-
curated labels given. However, the fine-tuning or few show prompting processes
for each model differed from each other in order to correspond to the
documentation for each LLM. GPT 3.5 Turbo and LLaMA-2 were the only models
that allowed fine-tuning that alters model parameters. For each of those
models, a system prompt was included that specified the role of the LLM to be
a financial chatbot that does not hallucinate information that is not included
in the provided context.

This method of fine-tuning only enhanced the model’s ability to answer
questions accurately given that it had access to the sections in the document
that contained the answer. This is because the context was included in the
given labels and concatenated to the prompt accordingly. The context was
included and given to the LLM the same way it would be in a traditional RAG
architecture, the only difference is that the context was given based on human
expertise instead of retrieved by an algorithm. Therefore, to develop an
optimized finance LLM, we need to develop a strong RAG model too, or our fine-
tuned model will not be able to infer the answer from an incorrect chunk from
the document.

###  4.2 Enhancing Retrieval

Although fine-tuning methods can enhance a model’s ability to answer questions
when provided with context, the overall performance will still suffer
significantly if the model cannot retrieve the relevant chunks that contain
the answer in the first place. In a traditional RAG system, the documents are
first divided into chunks and converted into embeddings, which are numerical
representations of the text. The most relevant chunks are found by conducting
a cosine similarity search between the query and all the embeddings. The
chunks with the most similar embeddings, measured through a cosine similarity
score, are what gets returned by the retrieval function. The LLM uses these
sections of the text as context to answer the question.

However, the simple RAG pipeline often fails for more complicated documents
and advanced question-answering. This is because the sections of the document
that most likely contain the answers, or the sections a human expert would
look to are not necessarily the sections with the most similar words. The
reality is much more nuanced than that as most similar does not necessarily
mean most relevant. The challenge is then to figure out how to develop an
algorithm that can account for such nuances. In this paper, we employed a
technique called Forward-looking active retrieval augmented generation (FLARE)
to try and address the pitfalls of traditional RAG techniques.

FLARE employs a much more active approach rather than a one-and-done retrieval
pipeline. Instead of doing a similarity search of just the query and document
embeddings, FLARE prompts the LLM to generate a hypothetical response from the
query without context, and then both the query and hypothetical response are
used to trigger the RAG step to search for the most similar chunks.161616FLARE
— “Advanced” RAG implemented from scratch https://ayushtues.medium.com/flare-
advanced-rag-implemented-from-scratch-07ca75c89800 Accessed on 2024-01-18 This
aspect is known as Hypothetical Document Embeddings(HyDE) and is a version of
query expansion. FLARE builds on top of this by setting a threshold when to
and when to not trigger retrieval. Only if the next generated tokens have a
probability under a certain threshold, meaning that the model is not confident
in the next predictions, it will go and try to retrieve relevant chunks from
the document. This way, the model does not have to rely on the initial chunks
it retrieved but can actively update the context based on how confident it is.

##  5 Evaluating Method

In assessing how well each LLM performs, we used a detailed method with three
measures: ROUGE-L, cosine similarity, and LLM evaluation. We looked at
datasets with questions, answers, and context made by human experts to see how
well the models understand and respond. ROUGE-L checked how closely the
model’s responses matched human answers, while cosine similarity checked how
well the model’s outputs aligned with human references. For LLM evaluation, we
prompted GPT 3.5 to give a score of 0 or 1 based on whether the model response
and the reference answer conveyed the same idea. We tested six versions of
each LLM, starting with 0 labeled data points and going up to 50, to see how
more labeled data affected performance. For fine-tuning, each model had its
own method, including few-shot prompting, OpenAI API-based fine-tuning, or
using the HuggingFace Transformer’s Trainer class. Some models, like GPT 3.5
Turbo and LLaMA-2, were fine-tuned with specific prompts to act as financial
chatbots. This thorough evaluation, considering both language and meaning,
showed how adding labeled data, from 0 to 50, impacted each LM’s performance.
We also conducted benchmarking on the Flare RAG dataset using a vector
database, employing a similar approach.

###  5.1 Choosing the Right Approach

There are various models available and different methods to improve each one
for your specific use case, each having its own trade offs. A key point is the
difference between open-source and closed-source LLMs and the implications it
has with respect to privacy. Many firms have prohibited the use of ChatGPT
because of concerns of data privacy as they might want to use these tools to
ask questions and interact with confidential documents. If data privacy is a
primary concern, then Open source models like LLAMA-2 are the only options as
they can be downloaded locally or hosted in a cloud based system that one has
control over. However, the primary trade off of these private models is that
it requires having access to more compute, usually several GPUs to have
comparable speed to closed source models, and this can lead to significant
additional costs. If data privacy is not as big of a concern, GPT and Claude
are great options, yet one needs to be mindful of the cost of API calls and
how that scales depending on the use case. Most open source models are
significantly smaller in size, in this paper we used the 7 billion parameter
version of LLAMA, while models like GPT have around 175 billion parameters.
However, through proper fine tuning and implementation of other techniques, a
smaller model can be optimized for a specific use case to be comparable to the
larger models. Ultimately, it is important to consider both your priorities
and resources available to choose the best method.

Figure 6: Besides Accuracy, Other Factors to Consider When Choosing your LLM
1818footnotemark: 18

##  6 Results

In the plots below, you can see the rouge score and the cosine similarity
score increases more or less when the number of labels increases,
demonstrating the effectiveness of fine tuning. To see the raw results and
code in more detail, please access it here.

Figure 7: Finance Bench Dataset (a) Claude Results

(b) Fine tuned GPT 3.5 Results

(c) Llama2 Results

(d) GPT4ALL Results

(e) FLARE Results

Figure 8: Rag Instruct Dataset (a) Claude Results

(b) Fine Tuned GPT 3.5 Results

(c) GPT4ALL Results

(d) FLARE Results

##  7 Conclusion

In summary, when we fine-tuned the models by incorporating feedback from
humans and adding more labeled examples, we consistently saw improved accuracy
across various datasets. Training the model by adding a few labeled samples in
edge cases or specific areas where the model struggled made a big difference.
By focusing on these weak points through repeated fine-tuning and adjustment
of prompts, the model got better over time. This iterative process, guided by
user feedback, played a crucial role in boosting the overall accuracy of the
model.

Another key finding was that simple RAG pipelines do not perform well on
domain specific questions and documents, so other techniques need to be
employed to develop a more accurate retrieval algorithm. A robust document
based question-answering system is contingent on having both a highly accurate
and specialized LLM as well as a robust retrieval method that provides the
most relevant context. To check out the detailed results and code, you can
find them by accessing the provided link.

##  8 Next Steps

For next steps, one thing we can do is more testing to tune different model
parameters to see if it would enhance performance. Only chunk size and chunk
overlap were adjusted in RAG, but most of the training parameters were kept at
the default for the training process. Testing out different embedding models,
or even fine tuning the embedding model for the finance specific domain would
be a method to try in the near future. Additionally, while supervised fine
tuning (SFT) was the primary technique used in this paper, it is also possible
to in corporate other methods such as unsupervised fine tuning and
reinforcement learning with human feedback into these models to further
improve performance. We are also looking to test out more methods to improve
retreival algorithms in addition to FLARE and HyDE to help find the best and
optimal chunk of text. These include implementing a re-ranking algorithm, such
as Cohere’s that will rearrange the document chunks based on relevant instead
of just similarity.191919Nils Reimers, Sylvie Shi, Lucas Fayoux, Elliott Choi,
Say Goodbye to Irrelevant Search Results: Cohere Rerank Is Here, May 2023
https://txt.cohere.com/rerank/ Since we are working with a variety of
financial documents with various different and complex sections, metadata
annotations could provide some value to further filter document chunks for
RAG. In summary, we will continue to strive for more ways to make these models
and the fine tuning process faster and more efficient while maintaining and
improving model performance.

##  9 References

  1. 1.

Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir
Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim
Rocktäschel, Sebastian Riedel, Douwe Kiela. Retrieval-Augmented Generation for
Knowledge-Intensive NLP Tasks, 2020.

  2. 2.

Disadvantages of RAG<EMAIL_ADDRESS>rag-5024692f2c53, Accessed on 2024-01-22.

  3. 3.

Pranab Islam1, Anand Kannappan, Douwe Kiela, Rebecca Qian, Nino Scherrer,
Bertie Vidgen. FINANCEBENCH: A New Benchmark for Financial Question Answering,
2023. arXiv:2311.11944.

  4. 4.

Edward Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean
Wang, Lu Wang, Weizhu Chen. LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE
MODELS, 2021. arXiv:2106.09685.

  5. 5.

Ayush Mangal. FLARE — “Advanced” RAG implemented from scratch, 2023.
https://ayushtues.medium.com/flare-advanced-rag-implemented-from-
scratch-07ca75c89800

  6. 6.

Quantized Fine-tuning on LLaMa-2 for RAG, 2023. https://medium.com/towards-
generative-ai/quantized-fine-tuning-llama-2-for-rag-question-
answering-426114daa09a

  7. 7.

Maxime Labonne. Fine-Tune Your Own Llama 2 Model in a Colab Notebook, 2023.
https://towardsdatascience.com/fine-tune-your-own-llama-2-model-in-a-colab-
notebook-df9823a04a32

  8. 8.

Philipp Schmid, Omar Sanseviero, Pedro Cuenca, Lewis Tunstall. Llama 2 is here
- get it on Hugging Face, 2023. https://huggingface.co/blog/llama2

  9. 9.

How to Fine-tune Llama 2 with LoRA for Question Answering: A Guide for
Practitioners, 2023. https://deci.ai/blog/fine-tune-llama-2-with-lora-for-
question-answering/

  10. 10.

Hugo Touvron, Thibaut Lavril, Gautier Izacard, Xavier Martinet, Marie-Anne
Lachaux, Timothee Lacroix, Baptiste Rozière, Naman Goyal, Eric Hambro, Faisal
Azhar, Aurelien Rodriguez, Armand Joulin, Edouard Grave, Guillaume Lample.
LLaMA: Open and Efficient Foundation Language Models, 2023. arXiv:2302.13971.

  11. 11.

Leonie Monigatti. A Guide on 12 Tuning Strategies for Production-Ready RAG
Applications, 2023. https://towardsdatascience.com/a-guide-on-12-tuning-
strategies-for-production-ready-rag-applications-7ca646833439

  12. 12.

Matt Ambrogi. 10 Ways to Improve the Performance of Retrieval Augmented
Generation Systems, 2023. https://towardsdatascience.com/10-ways-to-improve-
the-performance-of-retrieval-augmented-generation-systems-5fa2cee7cd5c

  13. 13.

Nathan Lambert, Louis Castricato, Leandro von Werra, Alex Havrilla.
Illustrating Reinforcement Learning from Human Feedback (RLHF), 2022.
https://huggingface.co/blog/rlhf

  14. 14.

Luyu Gao, Xueguang Ma, Jimmy Lin, Jamie Callan. Precise Zero-Shot Dense
Retrieval without Relevance Labels, 2022. arXiv:2212.10496.

  15. 15.

Sourab Mangrulkar, Sayak Paul. PEFT: Parameter-Efficient Fine-Tuning of
Billion-Scale Models on Low-Resource Hardware, 2023.
https://huggingface.co/blog/peft

  16. 16.

Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, Luke Zettlemoyer. QLORA:
Efficient Finetuning of Quantized LLMs, 2023. arXiv:2305.14314.

##  10 Appendix A: Dataset Descriptions

  1. 1.

Finance Bench Dataset

     * •

Description: Question and answer dataset for 10-K documents

     * •

Source: PatronusAI on HuggingFace

     * •

Size: 150 rows

     * •

URL: https://huggingface.co/datasets/PatronusAI/financebench

  2. 2.

RAG Instruct Benchmark Tester Dataset

     * •

Description: Question and answer dataset for various financial documents

     * •

Source: LLMWare on HuggingFace

     * •

Size: 200 rows

     * •

URL: https://huggingface.co/datasets/llmware/rag_instruct_benchmark_tester


# Nanoscale Reconfigurable Intelligent Surface Design and Performance Analysis
for Terahertz Communications

Xinying Ma, Zhi Chen, , and Chongwen Huang This work was supported in part by
the National Key Research and Development Program of China under Grant
2018YFB1801500, in part by the China Scholarship Council (CSC) under Grant
202006070151.X. Ma and Z. Chen are with National Key Laboratory of Science and
Technology on Communications, University of Electronic Science and Technology
of China, Chengdu 611731, China (e-mails<EMAIL_ADDRESS>chenzhi@uestc.edu.cn). Chongwen Huang is with College of Information Science
and Electronic Engineering, Zhejiang University, Hangzhou 310027, China
(e-mails: chongwenhuang@zju.edu.cn).

###### Abstract

Terahertz (THz) communications have been envisioned as a promising enabler to
provide ultra-high data transmission for sixth generation (6G) wireless
networks. To tackle the blockage vulnerability brought by severe attenuation
and poor diffraction of THz waves, a nanoscale reconfigurable intelligent
surface (NRIS) is developed to smartly manipulate the propagation directions
of incident THz waves. In this paper, the electric properties of the graphene
are investigated by revealing the relationship between conductivity and
applied voltages, and then an efficient hardware structure of electrically-
controlled NRIS is designed based on Fabry-Perot resonance model.
Particularly, the phase response of NRIS can be programmed up to 306.82
degrees. To analyze the hardware performance, we jointly design the passive
and active beamforming for NRIS aided THz communication system. Particularly,
an adaptive gradient descent (A-GD) algorithm is developed to optimize the
phase shift matrix of NRIS by dynamically updating the step size during the
iterative process. Finally, numerical results demonstrate the effectiveness of
our designed hardware architecture as well as the developed algorithm.

###### Index Terms:

Terahertz (THz) communications, nanoscale reconfigurable intelligent surface
(NRIS), hybrid beamforming, adaptive gradient descent (A-GD).

##  I Introduction

With the continuous explosion growth of data traffic in wireless
communications, sixth generation (6G) communication networks are expected to
meet a great deal of pressing requirements in the near future [1]. To meet the
bandwidth-hungry applications (e.g., on-chip communication, virtual reality,
kiosk downloading service, nanoscale localization and nanoscale biomedical
communication), terahertz (THz) frequency band (0.1-10 THz) has been regarded
as a prospective alternative to provide large spectrum bandwidth and support
ultra-high data transmission for 6G communication networks [2]. However, there
are still some imperative challenges existing in THz communications. On the
one hand, due to the high path attenuation and strong molecular absorption
effect experienced by THz waves, the transmission distance of THz
communications is limited within a small area, and thus is not applicable for
the practical communication scenarios [4], [5]. On the other hand, THz waves
at such a high frequency band undergo extremely poor diffraction and are
easily blocked by the obstacles. To tackle this issue, the concept of
nanoscale reconfigurable intelligent surface (NRIS) is newly proposed to
mitigate blockage vulnerability and improve coverage capability [6, 7, 8]. To
be specific, the NRIS, which consists of a large number of passive reflecting
elements is a kind of physical meta-surface and belongs to a special case of
conventional RIS except for the extremely small physical size. Each reflecting
element is capable of adjusting the phase shifts by using a smart central
processor [9]. In addition, NRIS is passive and lacks the active radio
frequency (RF) chains, and thus is more energy-efficient compared with
existing active devices, such as amplify-and-forward relaying [10] and massive
multiple-input multiple-output (MIMO). Therefore, the combination of NRIS and
THz communications is worthy of further exploration.

Deploying NRISs in the THz communication system is essential, but some
challenges also emerge accordingly. To realize reliable THz communications,
the channel state information (CSI) acquisition is the primary mission before
the data transmission begins. Different from conventional communication
systems with active devices, the main difficulty of channel estimation in
NRIS-enabled THz systems is that these reflecting elements are unable to
execute the signal processing. Prominently, by leveraging the sparse features
of THz MIMO channel, the work in [11] converts the channel estimation problem
into the sparse signal recovery problem, and a low complexity compressed
sensing based channel estimation scheme is developed to realize the efficient
signal reconstruction. Once the CSI is acquired at the base station (BS) side
or the mobile station (MS) side, the passive and active beamforming can be
jointly designed for NRIS-enabled MIMO systems. For instance, the work in [12]
optimizes the transmit beamforming at the BS and the passive beamforming at
the NRIS for the purpose of minimizing the total transmit power at the BS. To
reap the benefits of multiple NRISs, the authors aim to solve a new
cooperative multibeam multi-hop routing design problem and maximize the
minimum received signal power among all users [13, 14]. Besides, the authors
investigate the joint design of digital beamforming at the BS and analog
beamforming at NRISs for the NRIS-enabled THz MIMO systems from the
perspective of deep reinforcement learning [15]. In addition, other software
research directions are also investigated extensively, such as energy
efficiency optimization [8, 16], data rate maximization [17, 18, 19], secure
communication [20]. With regard to the hardware design of NRIS, many existing
works pay attention to testing NRIS characteristics and implementing NRIS
prototypes at THz frequency bands [21, 22, 23], but the algorithm design is
not actually taken into consideration. Apart from these aforementioned
research interests, the joint hardware design and hybrid beamforming for the
NRIS-empowered THz MIMO communication system is still treated as an open
problem.

In order to compensate for the research gap, the joint hardware design and
hybrid beamforming optimization for the NRIS-enabled THz MIMO system is
presented in this paper, _which is the first attempt to practically combine
the hardware characteristics of the NRIS and the software design together_. In
particular, a novel graphene-based hardware structure of NRIS with a wide
phase response range and a desired reflecting amplitude is designed.
Considering the hardware features of NRIS, we develop a downlink NRIS-enabled
THz MIMO system model and propose a gradient descent based method to optimize
the phase shifts of NRIS. Compared with the conventional MIMO system without
NRIS [24], [25], the maximum rate optimization problem of the NRIS-enabled THz
MIMO system involves multiple matrix variables, and thus is more
sophisticated. The main contributions of this paper can be summarized as
follows.

  * •

To begin with, we design a practical graphene-based NRIS hardware structure,
where its phase response can be controlled up to 306.82 degrees, and the
reflecting amplitude efficiency is more than 50% at 1.6 THz. Furthermore, the
design theory and working principle of the NRIS are also provided. Then, the
electric properties of the graphene are introduced by revealing the
relationship between conductivity and applied voltage, which is the foundation
of forming an electrically-controlled NRIS.

  * •

Based on the hardware features of NRIS, we employ singular value decomposition
(SVD) based method to obtain the optimally active beamforming at transceiver
and propose an adaptive gradient descent (A-GD) algorithm to achieve the
passive beamforming design for NRIS. Specifically, compared with conventional
gradient descent (C-GD) algorithm with the fixed step size, the proposed A-GD
algorithm turns out to be more efficient by dynamically updating the step size
during the iterative process, and thus is able to realize a better achievable
rate performance.

  * •

Finally, simulation results demonstrate that our designed NRIS hardware
structure with the practical phase response of 306.82 degrees achieves
basically identical performance in contrast with the ideal phase response of
360 degrees. More importantly, with the assistance of NRIS, the achievable
rate performance of our proposed A-GD algorithm greatly outstrips C-GD
algorithm and the conventional THz systems without NRIS.

The rest of this paper is organized as follows. In Section II, the electric
properties and hardware structure of graphene-based NRIS is presented. Section
III describes the NRIS based software design for THz communications. Finally,
the simulation results and conclusion are presented in Section IV and Section
V, respectively.

##  II Graphene Based Hardware Design of NRIS

In this section, an efficient graphene-based NRIS is designed that realizes a
wide range of amplitude response and phase response. The key component of NIRS
is the reflecting elements with sub-wavelength thickness, and each reflecting
element needs to be designed as a tunable resonant structure. In addition, by
arranging these reflecting elements in a specific way, the whole NIRS is
capable of achieving diverse functions, such as phase control, anomalous
reflection and planar focusing. Finally, the detailed working principle and
device performance can be presented in the following.

###  II-A Electric Properties of Graphene at THz Band

In order to achieve the beam controllability, tunable components are embedded
into the NRIS elements [26]. In general, semiconductor devices are extensively
utilized at microwave or millimeter wave frequency band (e.g., varactor diode
[27], switching diode [28]). Since the physical size of each reflecting
element at THz band is extremely small, the diodes and transistors can not be
integrated into such a nanoscale structure. In this case, graphene is a kind
of appropriate material to facilitate the NRIS with ultra-small size and
tunable property.

Graphene is a two-dimensional material consisting of a single layer of carbon
atoms. The conductivity of graphene can be altered through the applied voltage
bias in a relatively wide range. Therefore, graphene provides various resonant
states for each NRIS element. According to [29], the conductivity of graphene
at THz band can be written as

$\displaystyle\sigma{\rm{=}}\frac{{2{e^{2}}}}{{\pi{\hbar^{2}}}}{k_{B}}T\cdot\ln\left[{2\cosh\left({\frac{{{E_{F}}}}{{2{k_{B}}T}}}\right)}\right]\frac{i}{{\omega+i{\tau^{-1}}}},$
(1)

where ${e}$ is the elementary charge; ${\hbar}$ is the reduced Planck
constant; ${{{k_{B}}}}$ is the Boltzmann constant; ${T}$ is the temperature;
${{{E_{F}}}}$ is the Fermi level; ${\tau}$ is the relaxation time; and
${\omega}$ is the angular frequency, respectively. It can be concluded that at
a certain frequency point, the conductivity is only determined by Fermi level
[30]. Then we can get the following expression as

$\displaystyle\left|{{E_{F}}}\right|=\hbar{\nu_{F}}\sqrt{\pi{n_{d}}},$ (2)

where ${{\nu_{F}}}$ is the Fermi velocity and ${n_{d}}$ is the carrier density
which can be expressed as

$\displaystyle
n_{d}=\sqrt{n_{0}^{2}+\alpha_{c}{{\left|{{V_{{\rm{CNP}}}}-{V_{g}}}\right|}^{2}}},$
(3)

where ${{n_{0}}}$ is the residual carrier density and ${\alpha_{c}}$ is
capacitivity related to the electrode. Besides, ${V_{{\rm{CNP}}}}$ is the
compensating voltage, and ${{V_{g}}}$ is the applied voltage [31]. In summary,
the conductivity of graphene can be continuously changed by the applied
voltages, which is the foundation of forming an electrically controlled NRIS.

Figure 1: Hardware structure of a nanoscale reflecting element that consists
of graphene, quartz (substrate) and gold (ground plane) with
${a=66{\mathop{\rm um}\nolimits}}$, ${g=70{\mathop{\rm um}\nolimits}}$,
${t=38{\mathop{\rm um}\nolimits}}$ and ${{t_{m}}=1{\mathop{\rm
um}\nolimits}}$.

###  II-B Hardware Design of Graphene Based NRIS

(a)

(b)

(c)

Figure 2: Simulation results of the reflecting coefficient. (a) The response
of reflecting amplitude; (b) The response of phase shift; (c) Phase response
and reflecting amplitude versus Fermi level at 1.6 THz, where the phase
response is ${\left[{0^{\circ},306.82^{\circ}}\right]}$ with reflecting
amplitude more than ${50\%}$.

The EM responses of the reflecting elements play an important role in the
hardware structure of the NRIS. Fig. 1 shows a typical hardware design of a
NRIS element, which can be divided into three parts from top to the bottom:
the graphene layer, the substrate and the metallic ground plane. The resonance
model of this NRIS architecture can be described as a Fabry-Perot cavity,
where EM waves reflect back and forth between the top and the bottom surfaces.
In addition, the resonance responses are caused by constructive or destructive
interference of the multiple reflections [32]. In terms of such a reflecting
element structure as shown in Fig. 1, the phase response based on [33] can be
expressed as

$\displaystyle\varphi=m\pi-a{k_{0}}{\mathop{\rm
Re}\nolimits}\left({{n_{eff}}}\right),$ (4)

where ${m}$ is an integer; ${a}$ is the width of graphene patch; ${{k_{0}}}$
is the wave number of free space; and ${{{n_{eff}}}}$ is the effective
refraction index of the resonant structure, which is related to the effective
permittivity ${{\varepsilon_{eff}}}$ of the graphene. In light of [34], the
parameter ${{\varepsilon_{eff}}}$ can be written as

$\displaystyle{\varepsilon_{eff}}=1+\frac{{i\sigma_{c}}}{{\omega{\varepsilon_{0}}{t_{g}}}},$
(5)

where ${\sigma_{c}}$ is the conductivity and ${{{t_{g}}}}$ denotes the
thickness of graphene. Combining (4) and (5), the phase response can be
altered by the conductivity of graphene as well as the applied voltages.

The reflecting elements are simulated by leveraging the frequency domain
solver in the simulation environment of CST Microwave Studio 2016. It is worth
noting that a single reflecting element is unable to work since the miniature
size causes the strong scattering. As a result, the boundary condition of the
NRIS is set as ‘unit cell’ to mimic the repeated arrangement of the NRIS
elements. Fig. 2 illustrates the reflecting coefficients from 1.4 THz to 1.8
THz with various Fermi levels. By combining Fig. 2 (a) and Fig. 2 (b), our
designed NRIS performs relatively stable broadband characteristics. However, a
narrowband working mode of the NRIS elements is selected in this paper where
the center frequency is located at 1.6 THz. Fig. 2 (c) verifies that the
amplitude efficiency of our designed reflecting element at 1.6 THz is more
than ${50\%}$ and the phase response reaches to 306.82 degrees along with the
chemical potential ranging from 0 ev to 2 eV. Moreover, the discrete phase
shifts at 1.6 THz are also well-distributed with diverse Fermi levels, which
lays the foundation for the bit quantization operation of phase shifts.

Figure 3: Hardware design of the entire NRIS device that consists of a NRIS
array and a controller. Various phase distributions represented by different
color blocks are realized through applying different voltages to the nanoscale
reflecting elements.

Once the hardware structure of a single reflecting element is designed, the
whole NRIS is able to be accomplished by arranging massive reflecting elements
closely in an array structure, as shown in Fig. 3. Then, various beam steering
functions can be realized by controlling the phase response of all the NRIS
elements. But in practice, the appropriate number of the NRIS elements needs
to be carefully selected, which can make a better tradeoff between performance
and deployment cost. According to Fig. 2 (c), any expected phase shift within
the phase response range can be obtained via applying the voltages
continuously. However, the continuous phase control for each NRIS element
results in practical problems [35], such as hardware complexity, power
consumption, size limitation and the accuracy of phase control. To this end,
the discrete phase shifts are considered as the hardware structure of NRIS. We
define the discrete phase set of each NRIS element as ${{\cal
F}=\left\\{{0,{{{\varphi_{\max}}}\mathord{\left/{\vphantom{{{\varphi_{\max}}}{{2^{b}}}}}\right.\kern-1.2pt}{{2^{b}}}},\cdots,{{({2^{b}}-1){\varphi_{\max}}}\mathord{\left/{\vphantom{{({2^{b}}-1){\varphi_{\max}}}{{2^{b}}}}}\right.\kern-1.2pt}{{2^{b}}}}}\right\\}}$,
where ${\varphi_{\max}}$ is the maximum phase response and ${b}$ is the bit
quantization number. Then, we define the reflecting amplitude set as ${{\cal
A}}{\rm{=\\{}}{\mu_{1}},\cdots,{\mu_{\left|{{\cal F}}\right|}}{\rm{\\}}}$,
where $\left|{{\cal F}}\right|={2^{b}}$. From Fig. 2 (c) we can note that when
the distribution of the discrete phase shifts is determined, $\cal A$ can be
acquired accordingly. In other words, there is a fixed mapping relationship
between phase shift and reflecting amplitude for a specific hardware structure
of NRIS. Thus, the reflecting amplitude for each reflecting element can be
further defined as $\bar{\mu}={{\left({\sum\nolimits_{i=1}^{|{{\cal
F}}|}{{\mu_{i}}}}\right)}\mathord{\left/{\vphantom{{\left({\sum\nolimits_{i=1}^{|{{\cal
F}}|}{{\mu_{i}}}}\right)}{|{{\cal F}}|}}}\right.\kern-1.2pt}{|{{\cal F}}|}}$,
where the averaged amplitude $\bar{\mu}\in\left[{0.5,1}\right]$ is determined
by parameter $b$ with the given NRIS structure. Specifically, considering
these practical constraints, the maximum phase and amplitude response of NRIS
are set as 306.82 degrees and 0.8, respectively.

##  III System Model and Beamforming Design

In this section, we mainly introduce the NRIS-aided THz system model and
present a joint passive and active beamforming design framework.

###  III-A System Model

Figure 4: Illustration of a NRIS-assisted downlink THz MIMO system.

Considering a downlink THz MIMO system with hybrid beamforming architecture as
shown in Fig. 4, a BS employs ${{N_{{\mathop{\rm BS}\nolimits}}}}$ antennas to
serve a MS equipped with ${{N_{{\mathop{\rm MS}\nolimits}}}}$ antennas. Since
the LoS path between the BS and the MS is usually blocked by the obstacles, we
suppose that the NRIS is installed to assist this THz communication link,
which consists of ${{N_{{\mathop{\rm RIS}\nolimits}}}}$ passive reflecting
elements. In addition, a controller that connects the BS and the NRIS is also
required to realize the phase adjustment. Also, we assume that there are
${{M_{{\rm{BS}}}}}$ RF chains at BS side, and ${{M_{{\rm{MS}}}}}$ RF chains at
MS side. Due to the serious power consumption of RF circuits, the number of
antennas is larger than the number of the RF chains, i.e.
${{N_{{\rm{BS}}}}>{M_{{\rm{BS}}}}}$, ${{N_{{\rm{MS}}}}>{M_{{\rm{MS}}}}}$. When
the BS sends ${{N_{s}}}$ data streams
${{\bf{s}}\in{{\mathbb{C}}^{{N_{s}}\times 1}}}$ that satisfies
${\rm{E}}[{\bf{s}}{{\bf{s}}^{H}}]=\frac{1}{{{N_{s}}}}{{\bf{I}}_{{N_{s}}}}$,
the MS employs ${{M_{{\rm{MS}}}}}$ RF chains to receive the processed signals.
Thus, the received signal
${{{\bf{y}}_{r}}\in{{\mathbb{C}}^{{N_{{\mathop{s}\nolimits}}}\times 1}}}$ can
be expressed as

$\displaystyle{{\bf{y}}_{r}}=\sqrt{\rho}{\bf{W}}_{{\mathop{\rm
BB}\nolimits}}^{H}{\bf{W}}_{{\mathop{\rm
RF}\nolimits}}^{H}{{\bf{H}}_{2}}{\bf{\Phi}}{{\bf{H}}_{1}}{{\bf{F}}_{{\mathop{\rm
RF}\nolimits}}}{{\bf{F}}_{{\mathop{\rm
BB}\nolimits}}}{\bf{s}}+{\bf{W}}_{{\mathop{\rm
BB}\nolimits}}^{H}{\bf{W}}_{{\mathop{\rm RF}\nolimits}}^{H}{\bf{n}},$ (6)

where ${\rho}$ is transmit power;
${{{\bf{H}}_{1}}\in{{\mathbb{C}}^{{N_{{\mathop{\rm
RIS}\nolimits}}}\times{N_{{\mathop{\rm BS}\nolimits}}}}}}$ denotes BS-NRIS
channel; ${{{\bf{H}}_{2}}\in{{\mathbb{C}}^{{N_{{\mathop{\rm
MS}\nolimits}}}\times{N_{{\mathop{\rm RIS}\nolimits}}}}}}$ is NRIS-MS channel;
${{{\bf{F}}_{{\mathop{\rm RF}\nolimits}}}\in{{\mathbb{C}}^{{N_{{\mathop{\rm
BS}\nolimits}}}\times{M_{{\mathop{\rm BS}\nolimits}}}}}}$
(${{{\bf{F}}_{{\mathop{\rm BB}\nolimits}}}\in{{\mathbb{C}}^{{M_{{\mathop{\rm
BS}\nolimits}}}\times{N_{s}}}}}$) denotes the analog (digital) precoding
matrix; ${{{\bf{W}}_{{\mathop{\rm
RF}\nolimits}}}\in{{\mathbb{C}}^{{N_{{\mathop{\rm
MS}\nolimits}}}\times{M_{{\mathop{\rm MS}\nolimits}}}}}}$ and
${{{\bf{W}}_{{\mathop{\rm BB}\nolimits}}}\in{{\mathbb{C}}^{{M_{{\mathop{\rm
MS}\nolimits}}}\times{N_{s}}}}}$ are analog and digital combining matrices;
${{\bf{n}}\in{{\mathbb{C}}^{{N_{{\mathop{\rm MS}\nolimits}}}\times 1}}}$
represents the additive white Gaussian noise (AWGN) vector following the
distribution of ${{\cal C}{\cal
N}}\left({{\bf{0}},{\delta^{2}}{{\bf{I}}_{{N_{{\rm{MS}}}}}}}\right)$; and
${{\bf{\Phi}}={\mathop{\rm
diag}\nolimits}\left({{{{\mu{e^{j{\varphi_{1}}}},\mu{e^{j{\varphi_{2}}}},\cdots,\mu{e^{j{\varphi_{{N_{{\mathop{\rm
RIS}\nolimits}}}}}}}}}}}\right)}$ is a diagonal matrix with the dimension of
${{N_{{\mathop{\rm RIS}\nolimits}}}\times{N_{{\mathop{\rm RIS}\nolimits}}}}$,
respectively. Each entry
$\left\\{{\mu{e^{j{\varphi_{n}}}}}\right\\}_{n=1}^{{N_{{\rm{RIS}}}}}$ of
${{\bf{\Phi}}}$ indicates the reflecting coefficient of a NRIS element, and is
composed of the reflecting amplitude ${\mu}$ and the phase shift
$\left\\{{{\varphi_{n}}}\right\\}_{n=1}^{{N_{{\rm{RIS}}}}}$. Both ${\mu}$ and
${\varphi_{n}}$ are closely related with the hardware structure of NRIS that
is introduced in Section II.

###  III-B Channel Model

The NRIS-enabled THz MIMO channel model contains ${{{\bf{H}}_{1}}}$,
${\bf{\Phi}}$ and ${{{\bf{H}}_{2}}}$, and the cascaded channel is denoted as
${{\bf{H}}_{\rm{e}}}{\rm{=}}{{\bf{H}}_{2}}{\bf{\Phi}}{{\bf{H}}_{1}}$. We
assume that both ${{{\bf{H}}_{1}}}$ and ${{{\bf{H}}_{2}}}$ consist of a LoS
path and several non-line-of-sight (NLoS) paths, as we take the sparse nature
of the THz channel into consideration. On the basic of geometric channel model
[36], the BS-NRIS channel ${{{\bf{H}}_{1}}}$ can be written as

$\displaystyle{{\bf{H}}_{1}}=\sqrt{{N_{{\mathop{\rm
BS}\nolimits}}}{N_{{\mathop{\rm
RIS}\nolimits}}}}{\alpha_{0}}{{\bf{a}}_{{\mathop{\rm
R}\nolimits}}}\left({\theta_{{\mathop{\rm
R}\nolimits},0}^{1},\theta_{{\mathop{\rm
R}\nolimits},0}^{2}}\right){\bf{a}}_{{\mathop{\rm
B}\nolimits}}^{H}\left({\theta_{{\mathop{\rm
B}\nolimits},0}^{1},\theta_{{\mathop{\rm B}\nolimits},0}^{2}}\right)$
$\displaystyle+\sqrt{\frac{{{N_{{\mathop{\rm BS}\nolimits}}}{N_{{\mathop{\rm
RIS}\nolimits}}}}}{L}}\sum\limits_{l=1}^{L}{{\alpha_{l}}}{{\bf{a}}_{{\mathop{\rm
R}\nolimits}}}\left({\theta_{{\mathop{\rm
R}\nolimits},l}^{1},\theta_{{\mathop{\rm
R}\nolimits},l}^{2}}\right){\bf{a}}_{{\mathop{\rm
B}\nolimits}}^{H}\left({\theta_{{\mathop{\rm
B}\nolimits},l}^{1},\theta_{{\mathop{\rm B}\nolimits},l}^{2}}\right),$ (7)

where ${L}$ is the number of NLoS paths; ${\theta_{{\mathop{\rm
R}\nolimits}}^{1}}$ $({\theta_{{\mathop{\rm R}\nolimits}}^{2}})$ denotes the
angle of arrival (AoA) of ${{{\bf{H}}_{1}}}$ in the azimuth (elevation)
domain; and ${\theta_{{\mathop{\rm B}\nolimits}}^{1}}$ $({\theta_{{\mathop{\rm
B}\nolimits}}^{2}})$ denotes the angles of departure (AoD) of
${{{\bf{H}}_{1}}}$ in the azimuth (elevation) domain, respectively.
Considering the large number of THz array antennas, the uniform planar array
(UPA) structure is adopted as the array geometry. The normalized array
response for the ${{N_{x}}{N_{y}}}$-element UPA on $xy$-plane can be expressed
as

$\displaystyle\begin{array}[]{l}{{\bf{a}}_{{\rm{B}}}}{\rm{=}}\frac{{\rm{1}}}{{\sqrt{{N_{{\rm{BS}}}}}}}\left[{\cdots,{e^{\frac{{j2\pi
d}}{\lambda}\left({p\sin\left({\theta_{{\rm{B}}}^{2}}\right)\cos\left({\theta_{{\rm{B}}}^{1}}\right)+q\cos\left({\theta_{{\rm{B}}}^{2}}\right)}\right)}},\cdots}\right]^{T},\end{array}$
(9)

where $p\in\left[{0,{N_{x}-1}}\right]$, $q\in\left[{0,{N_{y}-1}}\right]$ and
${{N_{x}}{N_{y}}={N_{{\mathop{\rm BS}\nolimits}}}}$, respectively. The spacing
of THz array antenna is $d={\lambda\mathord{\left/{\vphantom{\lambda
2}}\right.\kern-1.2pt}2}$ where $\lambda$ is the incident wavelength. Similar
to (9), ${{{\bf{a}}_{{\mathop{\rm R}\nolimits}}}\left({\theta_{{\mathop{\rm
R}\nolimits}}^{1},\theta_{{\mathop{\rm R}\nolimits}}^{2}}\right)}$ also
employs the UPA structure, but the spacing of the adjacent NRIS elements is
the side length of each reflecting element. In addition, ${{\alpha_{0}}}$ is
the LoS path gain of ${{{\bf{H}}_{1}}}$. As discussed in [37],
${{\alpha_{0}}}$ consists of spreading loss and molecular absorbing loss,
which can be expressed as

${\alpha_{\rm{0}}}=\frac{c}{{4\pi
f{r_{0}}}}\cdot{e^{-\frac{1}{2}\kappa\left(f\right){r_{0}}}}\cdot{e^{-j2\pi
f{\tau_{{\rm{Los}}}}}},$ (10)

where ${c}$ is the speed of light; ${r_{0}}$ is the straight distance between
the BS and the MS; ${{\tau_{{\mathop{\rm
Los}\nolimits}}}={{r_{0}}\mathord{\left/{\vphantom{rc}}\right.\kern-1.2pt}c}}$
is the time-of-arrival of the LoS path; and ${{\kappa\left(f\right)}}$ is the
molecular absorbing coefficient. In addition, the channel gain
${{\alpha_{l}}}$ for the ${l}$th reflected path based on [37] and [38] can be
written as

$\displaystyle{\alpha_{l}}=\frac{c(\xi\left(f\right))}{{4\pi
f\left({{r_{1}}+{r_{2}}}\right)}}\cdot{e^{-\frac{1}{2}\kappa\left(f\right)\left({{r_{1}}+{r_{2}}}\right)-j2\pi
f{\tau_{{\mathop{\rm Ref}\nolimits}}}}},$ (11)

where $\xi\left(f\right)$ is the reflection coefficient of the reflecting
materials (e.g., concrete, plastic, glass); ${{{r_{1}}}}$ is the distance
between the transmitter and the reflecting material; ${{{r_{2}}}}$ is the
distance between the receiver and the reflecting material; and
${{\tau_{{\mathop{\rm Ref}\nolimits}}}={\tau_{{\mathop{\rm
Los}\nolimits}}}+{{\left({{r_{1}}+{r_{2}}-r}\right)}\mathord{\left/{\vphantom{{\left({{r_{1}}+{r_{2}}-r}\right)}c}}\right.\kern-1.2pt}c}}$
is the time-of-arrival of the reflected path, respectively. Besides, the
channel characteristics of ${{{\bf{H}}_{2}}}$ are identical to
${{{\bf{H}}_{1}}}$, so we can generate ${{{\bf{H}}_{2}}}$ in the same way. We
assume that the channel estimation problem has been extensively studied in
[11, 39], and these effective channel estimation methods can be well leveraged
in this paper.

###  III-C SVD-Based Active Beamforming Design

In light of the system model and hardware architecture of NRIS, the achievable
rate of the NRIS-aided THz MIMO system can be expressed as

$\displaystyle
R={\log_{2}}\left|{{{\bf{I}}_{{N_{s}}}}+\frac{\rho}{{{\delta^{2}}{N_{s}}}}{{\left({{{\bf{W}}^{H}}{\bf{W}}}\right)}^{-1}}{{\bf{W}}^{H}}}\right.$
$\displaystyle\quad\quad\quad\quad\quad\quad\left.{\times\left({{{\bf{H}}_{2}}{\bf{\Phi}}{{\bf{H}}_{1}}}\right){\bf{F}}{{\bf{F}}^{H}}{{\left({{{\bf{H}}_{2}}{\bf{\Phi}}{{\bf{H}}_{1}}}\right)}^{H}}{\bf{W}}}\right|,$
(12)

where we define ${{\bf{F}}={{\bf{F}}_{{\mathop{\rm
RF}\nolimits}}}{{\bf{F}}_{{\mathop{\rm BB}\nolimits}}}}$ and
${{\bf{W}}={{\bf{W}}_{{\mathop{\rm RF}\nolimits}}}{{\bf{W}}_{{\mathop{\rm
BB}\nolimits}}}}$. Then problem (III-C) can be reformulated as

$\displaystyle\left({{{\bf{\Phi}}^{{\rm{opt}}}},{{\bf{W}}^{{\rm{opt}}}},{{\bf{F}}^{{\rm{opt}}}}}\right)=\mathop{\arg\max}\limits_{{\bf{\Phi}},{\bf{W}},{\bf{F}}}R$
(13a)
$\displaystyle\;\;\quad\quad\quad\quad{\rm{s.t.}}\;\;{\varphi_{\max}}={306.82^{\rm{o}}},$
(13b)
$\displaystyle\;\;\quad\quad\quad\quad\quad\;\;\;{\bar{\mu}}=0.8,\;\forall
n=1,\ldots,{N_{{\rm{RIS}}}},$ (13c)
$\displaystyle\;\;\quad\quad\quad\quad\quad\;\;\;{\varphi_{n}}\in{{\cal
F}},\;\forall n=1,\ldots,{N_{{\rm{RIS}}}},$ (13d)
$\displaystyle\;\;\quad\quad\quad\quad\quad\;\;\left\|{\bf{F}}\right\|_{F}^{2}={N_{s}},$
(13e)

where (13b) is from our designed discrete phase response and (13c) stems from
our designed reflecting amplitude. Due to the non-convex and discrete
constraints, it is challenging to directly solve the problem (13).
Fortunately, one available way of settling such an optimization problem is to
first design hybrid beamforming ${{\bf{F}}}$ and ${{\bf{W}}}$, and then
optimize the phase shift matrix ${{\bf{\Phi}}}$, respectively.

Given a fixed ${{\bf{\Phi}}}$, the singular value decomposition (SVD) of the
cascaded channel ${{\bf{H}}_{\rm{e}}}$ can be written as

$\displaystyle{{\bf{H}}_{\mathop{\rm e}\nolimits}}$
$\displaystyle={\bf{U\Lambda}}{{\bf{V}}^{H}}$
$\displaystyle=\left[{{{\bf{U}}_{1}},{{\bf{U}}_{2}}}\right]\left[{\begin{array}[]{*{20}{c}}{{{\bf{\Lambda}}_{1}}}&{\bf{0}}\\\
{\bf{0}}&{{{\bf{\Lambda}}_{2}}}\end{array}}\right]{\left[{{{\bf{V}}_{1}},{{\bf{V}}_{2}}}\right]^{H}},$
(16)

where ${{\bf{U}}}$ is a ${{N_{{\mathop{\rm MS}\nolimits}}}\times G}$ unitary
matrix; ${{\bf{\Lambda}}}$ is a ${G\times G}$ dimensional matrix; ${{\bf{V}}}$
is a ${{N_{{\mathop{\rm BS}\nolimits}}}\times G}$ unitary matrix;
${{\bf{U}}_{1}}$ is a ${N_{{\rm{MS}}}}\times N_{s}$ submatrix of
${{\bf{U}}=\left[{{{\bf{U}}_{1}},{{\bf{U}}_{2}}}\right]}$; and
${{\bf{V}}_{1}}$ is a ${N_{{\rm{BS}}}}\times N_{s}$ submatrix of
${{\bf{V}}=\left[{{{\bf{V}}_{1}},{{\bf{V}}_{2}}}\right]}$, in which
$G\buildrel\Delta\over{=}rank\left({{{\bf{H}}_{\rm{e}}}}\right)$. Especially,
${{\bf{\Lambda}}_{1}}$ and ${{\bf{\Lambda}}_{2}}$ are $N_{s}\times N_{s}$ and
$(G-N_{s})\times(G-N_{s})$ diagonal matrices with the singular values arranged
in a decreasing order. According to [25], the optimal precoding matrix and
combining matrix can be expressed as

$\displaystyle{{\bf{F}^{{\rm{opt}}}}={{\bf{V}}_{1}}},\;\;\;{{\bf{W}^{{\rm{opt}}}}={{\bf{U}}_{1}}},$
(17)

where the transmit power satisfies
${\left\|{\bf{F}^{{\rm{opt}}}}\right\|_{F}^{2}={N_{s}}}$.

###  III-D Proposed A-GD for Passive Beamforming Design

Given the active beamforming matrices ${\bf{F}^{{\rm{opt}}}}$ and
${\bf{W}^{{\rm{opt}}}}$, the following target is to optimize the phase shift
matrix ${\bf{\Phi}}$. In addition, the achievable rate ${R}$ in (III-C) can be
rewritten as

$\displaystyle
R={\log_{2}}\left|{{{\bf{I}}_{{N_{s}}}}+\frac{\rho}{{{\delta^{2}}{N_{s}}}}{{\bf{\Lambda}}_{1}}{\bf{\Lambda}}_{1}^{H}}\right|.$
(18)

Subsequently, (18) can be further simplified as

$\displaystyle R$
$\displaystyle={\log_{2}}\left|{{{\bf{I}}_{{N_{s}}}}+\frac{\rho}{{{\delta^{2}}{N_{s}}}}{\bf{\Lambda}}_{1}^{2}}\right|$
$\displaystyle\mathop{\leq}\limits^{(a)}{N_{s}}{\log_{2}}\left({1+\frac{\rho}{{{\delta^{2}}{N_{s}}}}{\rm{tr}}\left({{\bf{\Lambda}}_{1}^{2}}\right)}\right)$
$\displaystyle\mathop{\leq}\limits^{(b)}{N_{s}}{\log_{2}}\left({1+\frac{\rho}{{{\delta^{2}}{N_{s}}}}{\rm{tr}}\left({{{\bf{H}}_{\rm{e}}}{\bf{H}}_{\rm{e}}^{H}}\right)}\right),$
(19)

where $(a)$ comes from Jensen’s inequality and $(b)$ takes the mark of
equality when $N_{s}=G$. Therefore, the optimization problem (13) can be
formulated as

$\displaystyle{{\bf{\Phi}}^{{\rm{opt}}}}=$
$\displaystyle\mathop{\arg\max}\limits_{\bf{\Phi}}\;\;{\rm{tr}}\left({{{\bf{H}}_{\rm{e}}}{\bf{H}}_{\rm{e}}^{H}}\right)$
(20a) $\displaystyle\;{\rm{s.t.}}\;\;{\varphi_{\max}}={306.82^{\rm{o}}},$
(20b) $\displaystyle\;\;\;\;\;\;\;\left|{\bar{\mu}}\right|=0.8,\;\forall
n=1,\ldots,{N_{{\rm{RIS}}}},$ (20c)
$\displaystyle\;\;\;\;\;\;\;\;{\varphi_{n}}\in{{\cal F}},\;\forall
n=1,\ldots,{N_{{\rm{RIS}}}}.$ (20d)

Nevertheless, it is worth noting that problem (20) is still a constrained
optimization problem, since ${\bf{\Phi}}$ possesses discrete phase shifts and
constant-magnitude entries. Let us define
${{\bm{\varphi}}\buildrel\Delta\over{=}\left[{{{{{\varphi_{1}},{\varphi_{2}},...,{\varphi_{{N_{{\mathop{\rm
RIS}\nolimits}}}}}}}}}\right]}$, and then consider ${{\bf{\Phi}}}$ as a
function of ${\bm{\theta}}$ where
${\bm{\theta}}={\bf{\Phi}}{{\bf{1}}_{{N_{{\rm{RIS}}}}}}={[\bar{\mu}{e^{j{\varphi_{1}}}},\bar{\mu}{e^{j{\varphi_{2}}}},\cdots,\bar{\mu}{e^{j{\varphi_{{N_{{\rm{RIS}}}}}}}}]^{T}}$.
Given this, we temporarily consider the continuous phase, and thus problem
(20) can be reformulated as

$\displaystyle\mathop{\arg\min\;}\limits_{\bm{\theta}}f{\rm{(}}{\bm{\theta}}{\rm{)=}}-{{\bm{\theta}}^{H}}{\bf{D}}{\bm{\theta}}$
(21a) $\displaystyle\;{\rm{s.t.}}\;\;{\varphi_{\max}}={306.82^{\circ}},$ (21b)
$\displaystyle\;\;\;\;\;\;\;\left|{{{\bm{\theta}}_{n}}}\right|=0.8,\forall
n=1,2,\cdots,{N_{{\rm{RIS}}}},$ (21c)

where $f{\rm{(}}{\bm{\theta}}{\rm{)}}$ is a compound function,
${\bf{D}}={{{\bf{\hat{D}}}}^{H}}{\bf{\hat{D}}}$ and
${\bf{\hat{D}}}=[\cdots,{({\bf{H}}_{1}^{T}\otimes{{\bf{H}}_{2}})_{:,(n-1){N_{{\rm{RIS}}}}+n}},\cdots]$,
$\forall n=1,2,\cdots,{N_{{\rm{RIS}}}}$.

Note that problem (21) still suffers from constant-magnitude constraint due to
the variable ${\bm{\theta}}$. To obtain an unconstrained problem,
$f\left({\bm{\theta}}\right)$ can be equivalently rewritten as

$\displaystyle f{\rm{(}}{\bm{\varphi}}{\rm{)}}$
$\displaystyle=-\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{\bm{\theta}}_{p}^{H}{{\bf{D}}_{p,q}}{{\bm{\theta}}_{q}}}}$
$\displaystyle=-{{\bar{\mu}}^{2}}\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{e^{-j{\varphi_{p}}}}{{\bf{D}}_{p,q}}{e^{j{\varphi_{q}}}}}}.$
(22)

Since ${\bf{D}}\in{{\mathbb{C}}^{{N_{{\rm{RIS}}}}\times{N_{{\rm{RIS}}}}}}$ is
a positive-definite Hermitian matrix, we can get ${\bf{D}}={{\bf{D}}^{H}}$.
Given continuous phase shifts
$\left\\{{{\varphi_{n}}}\right\\}_{n=1}^{{N_{{\rm{RIS}}}}}$, the ${n}$th
element of the gradient vector
${{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}$
can be calculated as

$\displaystyle\frac{{\partial
f{\rm{(}}{\bm{\varphi}}{\rm{)}}}}{{\partial{\varphi_{n}}}}=$
$\displaystyle{{\bar{\mu}}^{2}}j{e^{-j{\varphi_{n}}}}\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{{\bf{D}}_{n,q}}{e^{j{\varphi_{q}}}}}$
$\displaystyle-{{\bar{\mu}}^{2}}j{e^{j{\varphi_{n}}}}\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{{{\bf{D}}_{p,n}}{e^{-j{\varphi_{p}}}}}.$
(23)

After calculating all the $\partial
f({\bm{\varphi}})/\partial{\varphi_{n}},\forall
n=1,2,\cdots,{N_{{\rm{RIS}}}}$,
${{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}$
can be expressed as

$\displaystyle{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)={\left[{\frac{{\partial{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}}{{\partial{\varphi_{1}}}},\frac{{\partial{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}}{{\partial{\varphi_{2}}}},\cdots,\frac{{\partial{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}}{{\partial{\varphi_{{N_{{\mathop{\rm
RIS}\nolimits}}}}}}}}\right]^{T}}.$ (24)

On basis of the gradient direction
${{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}$,
the objective function ${{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}$ is
able to descend by replacing ${{\bm{\varphi}}}$ with
${{\bm{\varphi}}-\lambda{\mathop{\rm
diag}\nolimits}\left({{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({\bm{\varphi}}\right)}\right)}$,
where ${\lambda}$ is the iterative step size. During the ${i}$th iteration,
the updated ${{{\bm{\varphi}}^{\left({i+1}\right)}}}$ and the renewed
${{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i+1}}}\right)}$ can be
respectively written as

$\displaystyle{{\bm{\varphi}}^{i+1}}$
$\displaystyle={{\bm{\varphi}}^{i}}-\lambda{\nabla_{\bm{\varphi}}}f\left({{{\bm{\varphi}}^{i}}}\right)$
(25a) $\displaystyle f\left({{{\bm{\varphi}}^{i+1}}}\right)$
$\displaystyle=f\left({{{\bm{\varphi}}^{i}}-\lambda{\nabla_{\bm{\varphi}}}f({{{\bm{\varphi}}^{i}}})}\right).$
(25b)

Since the C-GD algorithm obtains the fixed step size ${{\lambda}}$ by
simulation experiment [6], it suffers from high complexity and low efficiency.
To this end, a novel A-GD algorithm is developed to determine the adaptive
step size ${{\lambda^{i}}}$. Based on above definition, (25) can be formulated
as

$\displaystyle
f{({{\bm{\varphi}}^{i+1}})}=-\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{{\left({{\bm{\theta}}_{p}^{i+1}}\right)}^{H}}{{\bf{D}}_{p,q}}{\bm{\theta}}_{q}^{i+1}}}$
$\displaystyle\quad\quad=-{{\bar{\mu}}^{2}}\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{{\bf{D}}_{p,q}}{e^{j\left({\varphi_{q}^{i}-\varphi_{p}^{i}}\right)+j\left({\Delta\varphi_{q}^{i}-\Delta\varphi_{p}^{i}}\right)}}}},$
(26)

where
${\Delta\varphi_{n}^{i}=-{\lambda^{i}}{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}\mathord{\left/{\vphantom{{\partial{\mathop{f}\nolimits}\left({{{\bf{\varphi}}^{i}}}\right)}{\partial\varphi_{n}^{i}}}}\right.\kern-1.2pt}{\partial\varphi_{n}^{i}}}}$
for ${n=1,2,\cdots,{N_{{\mathop{\rm RIS}\nolimits}}}}$. Note that
${{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i+1}}}\right)}$ is only
determined by ${{\lambda^{i}}}$ during $(i+1)$th iteration. Hence, the
optimization problem with regard to ${{\lambda^{i}}}$ can be expressed as

$\displaystyle{\lambda^{i}}\approx\mathop{\arg\min}\limits_{{\lambda^{i}}}=$
$\displaystyle-{{\bar{\mu}}^{2}}\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{{\bf{D}}_{p,q}}{e^{j\left({\varphi_{q}^{i}-\varphi_{p}^{i}}\right)}}}}$
$\displaystyle\quad\quad\quad\times{e^{j{\lambda^{i}}\left({\frac{{\partial
f{\rm{(}}{{\bm{\varphi}}^{i}}{\rm{)}}}}{{\partial\varphi_{p}^{i}}}-\frac{{\partial
f{\rm{(}}{{\bm{\varphi}}^{i}}{\rm{)}}}}{{\partial\varphi_{q}^{i}}}}\right)}}.$
(27)

To smartly control ${{\lambda^{i}}}$ during iterative process, we replace
${{e^{j{\lambda^{i}}\left[{{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}\mathord{\left/{\vphantom{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}{\partial\varphi_{p}^{i}}}}\right.\kern-1.2pt}{\partial\varphi_{p}^{i}}}-{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}\mathord{\left/{\vphantom{{\partial{\mathop{f}\nolimits}\left({{{\bf{\varphi}}^{i}}}\right)}{\partial\varphi_{q}^{i}}}}\right.\kern-1.2pt}{\partial\varphi_{q}^{i}}}}\right]}}}$
by the second-order Taylor expansion formulation. Then, (III-D) can be
approximated as

$\displaystyle{\lambda^{i}}$
$\displaystyle\approx\mathop{\arg\min}\limits_{{\lambda^{i}}}{\rm{}}-{{\bar{\mu}}^{2}}\sum\limits_{p=1}^{{N_{{\rm{RIS}}}}}{\sum\limits_{q=1}^{{N_{{\rm{RIS}}}}}{{{\bf{D}}_{p,q}}{e^{j\left({\varphi_{q}^{i}-\varphi_{p}^{i}}\right)}}}}$
$\displaystyle\quad\quad\quad\quad\quad\times\left({1+j{\lambda^{i}}\Gamma_{p,q}^{i}+\frac{{{{(j{\lambda^{i}}\Gamma_{p,q}^{i})}^{2}}}}{2}}\right)$
$\displaystyle=\mathop{\arg\min}\limits_{{\lambda^{i}}}{\rm{}}{C_{0}}+{C_{1}}{\lambda^{i}}+{C_{2}}{\lambda^{i}},$
(28)

where
$\Gamma_{p,q}^{i}={{{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}\mathord{\left/{\vphantom{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}{\partial\varphi_{p}^{i}}}}\right.\kern-1.2pt}{\partial\varphi_{p}^{i}}}-{{\partial{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}\mathord{\left/{\vphantom{{\partial{\mathop{f}\nolimits}\left({{{\bf{\varphi}}^{i}}}\right)}{\partial\varphi_{q}^{i}}}}\right.\kern-1.2pt}{\partial\varphi_{q}^{i}}}}}$.

Algorithm 1 Proposed A-GD Algorithm

0: ${{{\bf{H}}_{\rm{1}}}}$, ${{{\bf{H}}_{\rm{2}}}}$, ${\rho}$, ${{N_{s}}}$,
${{\delta^{2}}}$, ${{\cal F}}$, $b$, ${\varphi_{\max}}$, ${I}$,

1: Initialize ${\bf{D}}$, ${{\bf{W}^{{\rm{opt}}}}}$,
${{\bf{F}^{{\rm{opt}}}}}$,
${{\bf{\Phi}}}=\bar{\mu}{{\bf{I}}_{{N_{{\rm{RIS}}}}\times{N_{{\rm{RIS}}}}}}$,
${{{\bm{\varphi}}^{0}}={{\bf{0}}_{{N_{{\mathop{\rm RIS}\nolimits}}}\times
1}}}$, ${{{\mathop{f}\nolimits}_{\max}}=0}$, ${i=0}$,

2: while ${i\leq I_{max}}$ do

3: Calculate the gradient vector
${{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}$
in (24),

4: Calculate the step size ${{\lambda^{i}}}$ according to (32),

5: Update
${{{\bm{\varphi}}^{i+1}}={{\bm{\varphi}}^{i}}-{\lambda^{i}}{{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}}$,

6: Update
${{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i+1}}}\right)={\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}-{\lambda^{i}}{{\nabla_{\bm{\varphi}}}{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i}}}\right)}}\right)}$,

7: if
${{\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i+1}}}\right)>{{\mathop{f}\nolimits}_{\max}}}$
do

8:
${{{\mathop{f}\nolimits}_{\max}}={\mathop{f}\nolimits}\left({{{\bm{\varphi}}^{i+1}}}\right)}$,
${{{\bm{\varphi}}^{{\mathop{\rm opt}\nolimits}}}={{\bm{\varphi}}^{i+1}}}$,

9: end if

10: ${i=i+1}$,

11: end while

12: Map each entry of ${{{\bm{\varphi}}^{{\mathop{\rm opt}\nolimits}}}}$ into
discrete phase from ${{\cal F}}$,

12: ${{{\bf{\Phi}}^{{\mathop{\rm opt}\nolimits}}}}$, ${R}$

It is worth noting that there are two different cases for the quadratic
function in (III-D), including the positive value of term ${{C_{2}}}$ and the
negative value of term ${{C_{2}}}$. For these two cases, ${{\lambda^{i}}}$ can
be calculated as

$\displaystyle{\lambda^{i}}=\left\\{{\begin{array}[]{*{20}{c}}{{{-{C_{1}}}\mathord{\left/{\vphantom{{-{C_{1}}}{\left({2{C_{2}}}\right),{C_{2}}>0}}}\right.\kern-1.2pt}{\left({2{C_{2}}}\right),{C_{2}}>0}}}\\\
{{{\left|{{C_{1}}}\right|}\mathord{\left/{\vphantom{{\left|{{C_{1}}}\right|}{\left|{{C_{2}}}\right|}}}\right.\kern-1.2pt}{\left|{{C_{2}}}\right|}},\begin{array}[]{*{20}{c}}{}\hfil\end{array}{C_{2}}<0}\end{array}}\right.$
(32)

The main steps of our proposed A-GD algorithm are illustrated in Algorithm 1.

###  III-E Complexity Analysis

The main computational complexity of Algorithm 1 comes from updating
${{\mathop{f}\nolimits}({{{\bm{\varphi}}^{i+1}}})}$ in (25) and
${{\lambda^{i}}}$ in (32). Specifically, the complexity of calculating (25)
for each iteration can be expressed as
${\cal{O}}\left(4N_{{\rm{RIS}}}^{3}+9N_{{\rm{RIS}}}^{2}\right)$. For the sake
of updating step size ${{\lambda^{i}}}$, the complexity of executing (32) for
each iteration is
${\cal{O}}\left(2N_{{\rm{RIS}}}^{3}+8N_{{\rm{RIS}}}^{2}\right)$. As a
consequence, the total complexity of Algorithm 1 can be given by

$\displaystyle{\cal{O}}\left({I_{max}\left({6N_{{\rm{RIS}}}^{3}+17N_{{\rm{RIS}}}^{2}}\right)}\right).$
(33)

where $I_{max}$ represents the maximum iterations of our proposed A-GD
Algorithm.

##  IV Simulation Results

In this section, simulation results are provided to examine the effectiveness
of joint hardware and algorithm design for NRIS-enabled THz system, including
A-GD algorithm, C-GD algorithm, random phase algorithm and the conventional
THz system without NRIS. In addition, the distances of BS-NRIS, NRIS-MS and
BS-MS are set as ${{\bar{r}_{0}}=10\;m}$, ${{\tilde{r}_{0}}=20\;m}$, and
${{r_{0}}=25\;m}$ respectively, which can commendably meet the indoor
communication scenarios. The LoS path of BS-MS link is blocked by the
obstacle, and thus the NLoS paths are assisted by NRIS. Considering the sparse
nature of THz channel, we assume that ${{{\bf{H}}_{1}}}$ contains
${{L_{1}}=3}$ propagation paths, e.g., one LoS path and two NLoS paths. More
specifically, the complex gain of LoS path is generated based on (10) and the
complex gains of NLoS paths are computed by (III-C). The molecular absorbing
coefficient and the reflection coefficient of ceramic tile are set as
${\kappa(f)=0.2}$ and ${\xi(f)={10^{-6}}}$ [37]. Similarly, the parameter
settings of ${{{\bf{H}}_{2}}}$ are consistent with ${{{\bf{H}}_{1}}}$. We
further set ${{N_{{\rm{BS}}}}{\rm{=512}}}$, ${{N_{{\rm{RIS}}}}{\rm{=256}}}$,
${{N_{{\rm{MS}}}}{\rm{=32}}}$, ${{M_{{\rm{BS}}}}}=6$ and
${{M_{{\rm{MS}}}}}=4$. Here we define the signal-to-noise ratio (SNR) as
${{\rm{SNR}}=\rho/{\sigma^{2}}}$, and all simulation results are averaged over
1000 random channel realizations.

###  IV-A Hardware Influence for THz System

Fig. 5 investigates the achievable rate with the increasing number of the
maximum phase response ${{\varphi_{\max}}}$, which aims to validate the
effectiveness of the proposed hardware architecture mentioned in Section II.
From Fig. 5 we can note that the achievable rates of the considered NRIS-
enabled algorithms improve firstly and then converge to a fixed value.
Remarkably, the achievable rate of our proposed A-GD algorithm with
${{\varphi_{\max}}={306.82^{\rm{o}}}}$ have already converged, and possess the
same performance as the ideal case with
${{\varphi_{{\rm{ideal}}}}={360^{\rm{o}}}}$. Compared with low phase response
${{\varphi_{\max}}={60^{\rm{o}}}}$, the considered A-GD algorithm and the
random phase scheme with ${{\varphi_{\max}}={306.82^{\rm{o}}}}$ are able to
realize the achievable rate enhancement of 3.59 bps/Hz and 2.68 bps/Hz,
respectively. Hence, the numerical results reveal that our proposed graphene-
based NRIS is an efficient hardware structure.

Fig. 6 provides the achievable rate performance versus different bit
quantization values $b$. Fig. 6 indicates that the achievable rates of the
random phase scheme and the conventional THz system without NRIS are
insensitive to $b$. Instead, the achievable rates of A-GD and AO algorithms
are greatly affected by $b$. In the case of ${b=1}$, our developed A-GD
algorithm suffers from the obvious performance degradation due to the limited
quantization precision of NRIS. In contrast with ${b=2}$, our proposed A-GD
algorithm with ${b=1}$ endures about 0.93 bps/Hz performance penalty,
respectively. Intriguingly, the achievable rates of our proposed algorithms
with ${b=2}$ almost yields the similar performance compared with ${b\geq 3}$,
indicating that ${b=2}$ is sufficient to quantize the discrete phase for NRIS
in practice.

Figure 5: Achievable rate comparisons versus ${{\varphi_{\max}}}$. Figure 6:
Achievable rate comparisons versus ${b}$.

###  IV-B Performance Analysis for NRIS-Aided THz System

Figure 7: Achievable rate comparisons versus SNR. Figure 8: Achievable rate
comparisons versus ${{N_{{\rm{RIS}}}}}$.

Fig. 7 depicts the achievable rate versus diverse SNR in NRIS-aided THz MIMO
system. As shown in Fig. 7, the achievable rate of the NRIS-aided THz system
greatly outstrips the conventional THz system without NRIS that hardly meet
the future communication requirements. Numerically, the performance gap
between the random phase scheme and the THz system without NRIS is about 4.24
bps/Hz under the condition of SNR=10 dB. Meanwhile, Fig. 7 also indicates that
the achievable rate of our proposed A-GD algorithm is around 8.4 bps/Hz higher
than the random phase scheme, respectively. More importantly, by dynamically
adjusting the step size, our proposed A-GD algorithm is superior to the C-GD
algorithm with fixed step size, which demonstrates that our proposed
optimization algorithm can be employed to further enhance the achievable rate
performance for the NRIS-aided THz MIMO systems.

Fig. 8 discusses the achievable rate comparisons of the considered schemes
versus the number of NRIS elements. From Fig. 8, we can note that the
achievable rate of the THz system without NRIS case has the worst performance
due to the lack of NRIS, and remains unchanged along with the diverse values
of ${{N_{{\rm{RIS}}}}}$. In terms of these NRIS-aided algorithms, the
achievable rate of our developed A-GD algorithm outstrips the C-GD algorithm
and the random phase scheme. Moreover, when the number of reflecting elements
increases, the performance gaps between A-GD algorithm and the random phase
scheme become much larger. Specificall, our developed A-GD algorithm realizes
around 9.21 bps/Hz performance improvement compared with the random phase
scheme with ${{N_{{\rm{RIS}}}}{\rm{=192}}}$. Hence, NRIS can provides obvious
performance gain for THz communications, and our proposed software design is
capable of further improving the achievable rate. Last but not least, it
should be pointed out that the achievable rates of NRIS-aided algorithms will
converge to finite values even if the number of reflecting elements goes to
infinity, which is caused by the power budget limitation existing in practical
communications.

##  V Conclusion

This paper jointly considered the joint hardware and software design for the
NRIS-empowered THz MIMO communications. Considering the working principle of
the NRIS, we primarily probed into the characteristics of the practical
graphene-based NRIS. In light of these practical hardware constraints, the
A-GD algorithm was developed to settle the passive beamforming design at NRIS
and obtained much better performance than the C-GD algorithm. In the near
future, our research work will concentrate on the practical measurements for
the NRIS-empowered THz MIMO communication system.

## References

  * [1] X. You et al., “Towards 6G wireless communication networks: vision, enabling technologies, and new paradigm shifts,” _Sci. China Inf. Sci._ , vol. 64, no. 1, Jan. 2021.
  * [2] Z. Chen, X. Y. Ma, B. Zhang, et al., “A survey on terahertz communications,” _China Commun._ , vol. 16, no. 2, pp. 1-35, Feb. 2019.
  * [3] I. F. Akyildiz, J. M. Jornet, and C. Han, “Terahertz band: Next frontier for wireless communications,” _Phys. Commun. (Elsevier)_ , vol. 12, no. 4, pp. 16-32, 2014.
  * [4] I. F. Akyildiz, C. Han and S. Nie, “Combating the Distance Problem in the Millimeter Wave and Terahertz Frequency Bands,” _IEEE Commun. Mag._ , vol. 56, no. 6, pp. 102-108, June. 2018.
  * [5] C. Han and Y. Chen, “Propagation Modeling for Wireless Communications in the Terahertz Band,” _IEEE Commun. Mag._ , vol. 56, no. 6, pp. 96-101, Jun. 2018.
  * [6] C. Huang, A. Zappone, G. C. Alexandropoulos, et al., “Reconfigurable Intelligent Surfaces for Energy Efficiency in Wireless Communication,” _IEEE Trans. Wirel. Commun._ , vol. 18, no. 8, pp. 4157-4170, Aug. 2019.
  * [7] C. Liaskos, S. Nie, A. Tsioliaridou, A. Pitsillides, S. Ioannidis and I. Akyildiz, “A New Wireless Communication Paradigm through SoftwareControlled Metasurfaces,” _IEEE Commun. Mag._ , vol. 56, no. 9, pp. 162-169, Sept. 2018.
  * [8] L. Dai, B. Wang, M. Wang, et al., “Reconfigurable Intelligent Surface-Based Wireless Communications: Antenna Design, Prototyping, and Experimental Results,” _IEEE Access_ , vol. 8, pp. 45913-45923, 2020.
  * [9] C. Huang, S. Hu, G. C. Alexandropoulos, et al., “Holographic MIMO surfaces for 6G wireless networks: opportunities, challenges, and trends,” _IEEE Wireless Communications_ , vol. 27, no. 5, pp. 118-125, Oct. 2020.
  * [10] F. Gao, T. Cui and A. Nallanathan, “On channel estimation and optimal training design for amplify and forward relay networks,” _IEEE Trans. Wirel. Commun._ , vol. 7, no. 5, pp. 1907-1916, May 2008.
  * [11] X. Ma, Z. Chen, W. Chen, et al., “Joint Channel Estimation and Data Rate Maximization for Intelligent Reflecting Surface Assisted Terahertz MIMO Communication Systems,” _IEEE Access_ , vol. 8, pp. 99565-99581, May 2020.
  * [12] Q. Wu and R. Zhang, “Intelligent Reflecting Surface Enhanced Wireless Network via Joint Active and Passive Beamforming,” _IEEE Trans. Wirel. Commun._ , vol. 18, no. 11, pp. 5394-5409, Nov. 2019.
  * [13] W. Mei and R. Zhang, “Multi-Beam Multi-Hop Routing for Intelligent Reflecting Surfaces Aided Massive MIMO,” _IEEE Trans. Wirel. Commun._ , vol. 21, no. 3, pp. 1897-1912, March 2022.
  * [14] W. Mei and R. Zhang, “Cooperative Beam Routing for Multi-IRS Aided Communication,” _IEEE Wirel. Commun. Lett._ , vol. 10, no. 2, pp. 426-430, Feb. 2021.
  * [15] C. Huang et al., “Multi-Hop RIS-Empowered Terahertz Communications: A DRL-Based Hybrid Beamforming Design,” _IEEE J. Sel. Areas Commun._ , vol. 39, no. 6, pp. 1663-1677, June 2021.
  * [16] C. Huang, G. C. Alexandropoulos, A. Zappone, M. Debbah and C. Yuen, “Energy Efficient Multi-User MISO Communication Using Low Resolution Large Intelligent Surfaces,” in _Proc. IEEE GLOBECOM Workshops_ , pp. 1-6, 2018.
  * [17] Q. Wu, R. Zhang, “Intelligent reflecting surface enhanced wireless network: Joint active and passive beamforming design,” in _Proc. IEEE GLOBECOM_ , pp 1-6, 2018.
  * [18] X. Ma, Z. Chen, W. Chen, et al., “Intelligent Reflecting Surface Enhanced Indoor Terahertz Communication Systems,” _Nano Commun. Netw._ , vol. 24, pp. 100284, May. 2020.
  * [19] C. Pan et al., “Multicell MIMO Communications Relying on Intelligent Reflecting Surfaces,” _IEEE Trans. Wirel. Commun._ , vol. 19, no. 8, pp. 5218-5233, Aug. 2020.
  * [20] H. Shen, W. Xu, S. Gong, Z. He and C. Zhao, “Secrecy Rate Maximization for Intelligent Reflecting Surface Assisted Multi-Antenna Communications,” _IEEE Commun. Lett._ , vol. 23, no. 9, pp. 1488-1492, Sept. 2019.
  * [21] L. Liang, M. Qi, J. Yang, et al., “Anomalous Terahertz Reflection and Scattering by Flexible and Conformal Coding Metamaterials,” _Adv. Opt. Mater._ , vol. 3, no. 10, pp. 1311-1311, 2015.
  * [22] S. Liu, L. Zhang, Q. Yang, et al., “Frequency dependent dual functional coding metasurfaces at terahertz frequencies,” _Adv. Opt. Mater._ , vol. 4, no. 12, pp. 1965-1973, 2016.
  * [23] Z. Chen, X. Ma, C. Han and Q. Wen, “Towards intelligent reflecting surface empowered 6G terahertz communications: A survey,” _China Commun._ , vol. 18, no. 5, pp. 93-119, May 2021.
  * [24] A. Goldsmith, S. A. Jafar, N. Jindal and S. Vishwanath, “Capacity limits of MIMO channels,” _IEEE J. Sel. Areas Commun._ , vol. 21, no. 5, pp. 684-702, Jun. 2003.
  * [25] O. E. Ayach, S. Rajagopal, S. Abu-Surra, et al., “Spatially Sparse Precoding in Millimeter Wave MIMO Systems,” _IEEE Trans. Wirel. Commun._ , vol. 13, no. 3, pp. 1499-1513, Mar. 2014.
  * [26] H. Chen, A. J. Taylor, N. Yu, “A review of metasurfaces: physics and applications,” _Rep. Prog. Phys._ , vol. 79, no. 7, pp. 076401, Jun. 2016.
  * [27] W. Yang, X. Gao, “A Reconfigurable Polarization Converter Based on Active Metasurface,” _Cross Strait Quad-Regional Radio Science and Wireless Technology Conference (CSQRWC)_ , pp. 1-2, Jul. 2018.
  * [28] L. Li, T. Cui, W. Ji et al., “Electromagnetic reprogrammable codingmetasurface holograms,” _Nat. Commun._ , vol. 8, no. 1, pp. 197, Aug. 2017.
  * [29] H. Wong, D. Akinwande, “Carbon Nanotube and Graphene Device Physics,” _Cambridge University Press_ , 2010.
  * [30] D. K. Efetov, P. Kim, “Controlling electron-phonon interactions in graphene at ultrahigh carrier densities,” _Phys. Rev. Lett._ , vol. 105, no. 25, pp. 256805, Dec. 2010.
  * [31] S. Lee, M. Choi, T. Kim et al., “Switching teraherz waves with gate-controlled active graphene metamaterials,” _Nat. Mater_ , vol. 11, pp. 936-941, Sep. 2012.
  * [32] Y. Yang, W. Wang, P. Moitra et al., “Dielectric Meta-Reflectarray for Broadband Linear Polarization Conversion and Optical Vortex Generation,” _Nano Lett._ , vol.14, no.3, pp. 1394-1399, Feb. 2014.
  * [33] A. Pors, S. I. Bozhevolnyi, “Plasmonic metasurfaces for efficient phase control in reflection,” _Opt. Express_ , vol. 21, no. 22, pp. 27438-27451, Nov. 2013.
  * [34] Z. Li, K. Yao, F. Xia et al., “Graphene Plasmonic Metasurfaces to Steer Infrared Light,” _Sci. Rep._ , vol. 5, no. 12423, Jul. 2015.
  * [35] B. Di, H. Zhang, L. Song, et al., “Hybrid Beamforming for Reconfigurable Intelligent Surface based Multi-User Communications: Achievable Rates With Limited Discrete Phase Shifts,” _IEEE J. Sel. Areas Commun._ , vol. 38, no. 8, pp. 1809-1822, Aug. 2020.
  * [36] A. A. M. Saleh and R. Valenzuela, “A Statistical Model for Indoor Multipath Propagation,” _IEEE J. Sel. Areas Commun._ , vol. 5, no. 2, pp. 128-137, Feb. 1987.
  * [37] C. Han, A. O. Bicen, I. F. Akyildiz, “Multi-Ray Channel Modeling and Wideband Characterization for Wireless Communications in the Terahertz Band,” _IEEE Trans. Wirel. Commun._ , vol. 14, no. 5, pp. 2402-2412, Dec. 2015.
  * [38] W. Tang, M. Chen, X. Chen, et al., “Wireless Communications With Reconfigurable Intelligent Surface: Path Loss Modeling and Experimental Measurement,” _IEEE Trans. Wirel. Commun._ , vol. 20, no. 1, pp. 421-439, Jan. 2021.
  * [39] Z. Wang, L. Liu and S. Cui, “Channel Estimation for Intelligent Reflecting Surface Assisted Multiuser Communications: Framework, Algorithms, and Analysis,” _IEEE Trans. Wirel. Commun._ , vol. 19, no. 10, pp. 6607-6620, Oct. 2020.